mattn / go-gtk

Go binding for GTK
http://mattn.github.com/go-gtk
BSD 3-Clause "New" or "Revised" License
2.11k stars 248 forks source link

pixbuf memory leaks #170

Open raichu opened 11 years ago

raichu commented 11 years ago

I'm trying to display an image, whose size adapts to window size. But after a few resizes, the memory usage reaches 1GB!

What is the proper way of loading a pixpuf, scaling it and putting in into an image object? The obvious way (just doing them in sequence) doesn't work even with Clear on image before changing the pixbuf of the image object.

gdk_pixbuf_unref and gdk_pixbuf_ref aren't exposed, so I don't think there is any way of preventing memory leaks from Go side. Maybe using SetFinalizer for pixbufs is a good way, along with adding Ref and Unref methods.

raichu commented 11 years ago

Nope, calling Unref on the pixbuf returned by ScaleSimple after assinging it to the image worked!

raichu commented 11 years ago

I checked a python implementation and it doesn't require to call Unref. Maybe it's indeed best to set finalizer Unref for all objects?

mattn commented 11 years ago

I checked a python implementation and it doesn't require to call Unref. Maybe it's indeed best to set finalizer Unref for all objects?

Yes, currently you must call runtime.SetFinalizer if you want. But it's todo

mattn commented 9 years ago

GdkPixbuf is inherit GObject. So you can call pb.Ref() or pb.Unref().