Re: [gtkmm] how to free a pixbuf



On Wed, Oct 15, 2003 at 10:26:30AM -0400, Silviu D Minut wrote:
> I know. In your example, the RefPtr is a local variable in some function.
> In my case, as I mentioned, it is a member in a class, so it does not go
> out of scope right after the image has been read.

That doesn't matter. If your object goes out of scope, the pixbuf will
be freed if there are no more references to it. If you reassign the
pixbuf, the old one should be released too, if there are no more
references to it. That means:

> class MyClass : public Gtk::Window
> {
>     Glib::RefPtr<Gdk::Pixbuf> pixbuf_;
>     Gtk::DrawingArea * Darea;
> 
>     void load_image(const char * file){
> 	pixbuf_=Gdk::Pixbuf::create_from_file(file);
> 	// more stuff
>     }
> 
>     void on_Darea_expose_event() {
> 	// display pixbuf_ here, and other stuff
>     }
> };

If you call MyClass::load_image(file) twice, pixbuf_ gets reassigned and
the old content gets destroyed (if there are no more references to it).
If this does not work, you should write a test case in bugzilla, like MC
said.

Regards.

-- 
Simon Fuhrmann | NightSlayer at gmx.de | http://www.dismember.de
All people talk about the real life, but where can I download it?



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]