librelist archives

« back to archive

mleaks in green_shoes

mleaks in green_shoes

From:
Régis d'Aubarède
Date:
2011-07-25 @ 22:23
Hello,

For detect where come from memory leaks, I try the MemoryProfiler
found at
   http://scottstuff.net/blog/2006/08/17/memory-leak-profiling-with-rails
and  modified for spy Array class :


--------------------------------------------------------------------------------------
require 'green_shoes'
#require 'profile'
class MemoryProfiler
  DEFAULTS = {:delay => 2, :string_debug => true}
  def self.start(opt={})
    opt = DEFAULTS.dup.merge(opt)

    Thread.new do
      prev = Hash.new(0)
      curr = Hash.new(0)
      curr_strings = ""
      delta = Hash.new(0)
      h={}
      file = File.open('memory_profiler.log','w')

      loop do
        begin
          GC.start
          curr.clear

          curr_strings = [] if opt[:string_debug]

          ObjectSpace.each_object do |o|
            curr[o.class] += 1 #Marshal.dump(o).size rescue 1
            if opt[:string_debug]
              if o.class == Array && ! h[o.to_s]
                curr_strings << "\n" << o.to_s  # !!!!!! my modif
                h[o.to_s]=1                            # !!!!!!
              end
            end
          end

          if opt[:string_debug]
            File.open("memory_profiler_strings.log.#{Time.now.to_i}",'w') do
|f|
                f.puts curr_strings
            end
            curr_strings=""
          end

          delta.clear
          (curr.keys + delta.keys).uniq.each do |k,v|
            delta[k] = curr[k]-prev[k]
          end

          file.puts "Top 20"
          delta.sort_by { |k,v| -v.abs }[0..19].sort_by { |k,v| -v}.each do
|k,v|
            file.printf "%+5d: %s (%d)\n", v, k.name, curr[k] unless v == 0
          end
          file.flush

          delta.clear
          prev.clear
          prev.update curr
          GC.start
        rescue Exception => err
          STDERR.puts "** memory_profiler error: #{err}"
        end
        sleep opt[:delay]
      end
    end
  end
end

Shoes.app  do
    @st=stack
    @r=("ddddd,eeee"*10).split(',')
    every(0.1) {
        @st.clear { ([Time.now.to_f.to_s]+@r).each { |mess| flow { para
mess  }  } }
    }
    timer(100) { exit! }
    MemoryProfiler.start
end

--------------------------------------------------------------------------------------

It seem that there a a lot of list of slot, begining biger and biger....

by


-- 

- - - - - - - - - - - - - - - - -
 __   ___  __     __
|__) |__  / _` | /__`
|  \ |___ \__> | .__/

- - - - - - - - - - - - - - - - -

Re: [shoes] mleaks in green_shoes

From:
ashbb
Date:
2011-07-26 @ 13:07
Hi Régis,

Thank you for pointing out the issue.
I think this is not an issue of Slot.
Try out the following. You will find the same issue.

require 'green_shoes'
Shoes.app do
  every do
    o = oval 100, 100, 100
    o.clear
  end
end

The Shoes::Basic#clear method calls the Gtk::Image#clear method directly.


http://ruby-gnome2.sourceforge.jp/hiki.cgi?cmd=view&p=Gtk%3A%3AImage&key=Gtk%3A%3AImage#clear

It looks to work well, but not seem to free memory immediately...

I've been looking for a solution, but no luck so far. Need to study more...

ashbb