Hi, My friend and I have been writing an application that makes extensive use of gdkpixbuf's, but they never get de-allocated. I'm not entirely sure how the garbage-collector works internally in ruby, but my program quickly grows to over 114M pretty routinely. My friend wrote a simple demonstration script: require 'gtk2' Gtk.init path = ARGV.pop raise "Pass a large image on the command line" unless path puts "Look at how much memory I'm using, then press enter" gets #1 buf = Gdk::Pixbuf.new( path ) puts "Now I've allocated the pixbuf, I should be using more memory." puts "Hit enter to dereference the pixbuf." gets #2 buf = nil puts "Done. Press enter to exit." gets #3 Ok, here's the memory usage between various stages: 1: 1000 17271 0.3 2.4 15744 9312 pts/5 S+ 23:03 0:00 ruby pixbuf.rb 2: 1000 17271 0.3 4.1 22448 16228 pts/5 S+ 23:03 0:00 ruby pixbuf.rb 3: 1000 17271 0.3 4.1 22448 16228 pts/5 S+ 23:03 0:00 ruby pixbuf.rb Now this example is much more trivial than the program we're trying to right, but they're both having this issue w/ the pixbuf's never being de-allocated. Is this a known bug? Is there something we can do to force the GC to take care of them? Thanks, Cameron M.
on 2006-05-10 09:09
on 2006-05-10 11:08
2006/5/10, Cam <email@example.com>: > path = ARGV.pop > > > Now this example is much more trivial than the program we're trying to > right, but they're both having this issue w/ the pixbuf's never being > de-allocated. Is this a known bug? Is there something we can do to > force the GC to take care of them? I can only say something about your short demo piece because I don't have the other code. It's quite unlikely that you see the GC kick in before program termination here. GC kicks in when the interpreter decides to do it - not necessarily soon after an object has become unreachable. This is really only a problem if you have a long running version and it keeps using more memory over time. I suggest you modify your script by removing lines with "gets" and put the whole thing in a loop say 10,000 times. Then watch how memory usage develops. If it's linearly increasing your chances are that there is a bug in Gdk or you're using it the wrong way (i.e. do not release Gdk resources as required by the lib). HTH robert
on 2006-05-10 23:44
Hey, On 5/10/06, Robert K. <firstname.lastname@example.org> wrote: > resources as required by the lib). I had thought about the GC not having time to free up the resources, but I assumed that the GC would start doing its magic whenever the program was idle. Anyway, the real program is much more complex than this, and it should be having plenty of time for GC. Is it common for a library to require releasing of resources? I will look into that further, although I don't *think* i saw anything about that in the docs. Thanks, Cameron M.