Re: Memory leak of RefPtr?



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



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