#13 pixmap memory leak in X server

closed
Masao Mutoh
ruby-gnome (11)
5
2002-12-23
2002-12-21
Mike Wyer
No

Gtk::Pixmaps don't appear to free up their allocated
memory in the X server until the program exits, even if
they are "destroy"ed while the program is running.

The following code will cause the X server to bloat
(RSS goes from 35M (inc 32M framebuffer), to 300M in
about 30s). Just give it a filename for a picture (any
old jpeg will do).

Obviously this only affects code that creates and
destroys lots of pixmaps, but my little image browser
can easily crash the X server when it runs out of memory.

#!/usr/bin/env ruby

require 'gtk'
require 'gdk_pixbuf'

im = Gdk::Pixbuf.new(ARGV[0])
window = Gtk::Window.new(Gtk::WINDOW_TOPLEVEL)
frame = Gtk::Frame.new("Mem leak test")
widget = Gtk::Pixmap.new(*im.to_pixmap_and_mask)
frame.add widget.show
window.add frame.show
window.show
count = 1
Gtk::timeout_add(100) do
tmp = frame.child
if tmp
frame.remove tmp
tmp.destroy
GC.start
end
widget = Gtk::Pixmap.new(*im.to_pixmap_and_mask)
frame.add widget.show
count +=1
count <= 50
end

Gtk.main

Discussion

  • Masao Mutoh
    Masao Mutoh
    2002-12-23

    Logged In: YES
    user_id=495147

    Hi,

    Thanks for your reporting.

    This problem is caused that Gdk::Pixbuf#to_pixmap_and_mask
    returns the copied Gdk::Pixmap/Gdk::Bitmap and which aren't
    free when GC is called.

    I think this is a serious bug, but it is difficult to fix
    this with Ruby/GTK's current memory management system.
    And I don't have enough times to fix this problem now....

    If you can use Ruby/GTK2, please try Ruby/GTK2
    as this problem has already fixed.

    Or try a workarround as follows.

    > #!/usr/bin/env ruby
    >
    > require 'gtk'
    > require 'gdk_pixbuf'
    >
    > im = Gdk::Pixbuf.new(ARGV[0])
    > window = Gtk::Window.new(Gtk::WINDOW_TOPLEVEL)
    > frame = Gtk::Frame.new("Mem leak test")

    pixmap, mask = im.to_pixmap_and_mask
    widget = Gtk::Pixmap.new(pixmap, mask)

    > frame.add widget.show
    > window.add frame.show
    > window.show
    > count = 1
    > Gtk::timeout_add(100) do
    > tmp = frame.child
    > if tmp
    > frame.remove tmp
    > tmp.destroy
    > GC.start
    > end

    widget = Gtk::Pixmap.new(pixmap, mask)

    > frame.add widget.show
    > count +=1
    > count <= 50
    > end
    >

    Thanks,
    Masao

     
  • Masao Mutoh
    Masao Mutoh
    2002-12-23

    • assigned_to: klamath --> mutoh
    • status: open --> closed