Re: Memory leak of RefPtr?



Briefly: it is impossible to create a memory leak with RefPtr as long
as you use pointers created by Gtkmm and don't create your own from
raw pointers.  (Creating by copy constructor from other RefPtr's is
OK.)

Actually, it's rather easy to have memory leaks with RefPtrs, all you need
is a circular reference, and the ref counting won't work any more.

Greets,

Lieven van der Heide


On Fri, 25 Aug 2006 00:01:44 +0200, Paul Pogonyshev <pogonyshev gmx net>
wrote:

Rose Cumming wrote:

Thanks for your reply.

So even I keep calling this function?

void some_function()
{
   display_ =
      Gdk::Pixbuf::create
        (view_, get_default_colormap(), 0,0,0,0, 500, 500);
}

say display_ is a member variable of a class that stays in scope for the
duration of my application,
Glib::RefPtr<Gdk::Pixbuf> display_;

No memory leak?

Destructor of Glib::RefPtr unreferences pointed object.  Assignment
references assigned object.  However, constuctor doesn't reference,
so you have to be sure you reference the object yourself or there is
a reference already.

Briefly: it is impossible to create a memory leak with RefPtr as long
as you use pointers created by Gtkmm and don't create your own from
raw pointers.  (Creating by copy constructor from other RefPtr's is
OK.)

Paul
_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list




--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/



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