On Thu, 2006-08-24 at 20:11 +0000, Rose Cumming wrote:
> Hello,
> 
> I'm not familiar with smart pointer. I'm just wondering will the following 
> code cause memory leak?
> 
> For example,
> 
> in my class, I have a member variable
> 
> Glib::RefPtr<Gdk::Pixbuf> viewBuffer_;
> 
> in the constructor of this class I do this,
> 
> viewBuffer_ = Gdk::Pixbuf::create(Gdk::COLORSPACE_RGB, false, 8, 100, 100);
> 
> in a member function of this class I do this,
> 
> void draw()
> {
>    Glib::RefPtr<Gdk::Pixbuf> *buffer;
>    someObjectPointer_->getImage(&buffer);

You are using a pointer to the RefPtr. Like any use of a pointer like
this you would need to document whether the caller should delete the
instance that it has been given (e.g. "delete buffer" to delete the
refptr to the buffer, hence deleting one reference to the buffer
itself.).


But it's far easier to just enjoy the benefits of using the
smartpointer:

Glib::RefPtr<Gdk::Pixbuf> buffer = someObjectPointer_->getImage();

or 

Glib::RefPtr<Gdk::Pixbuf> buffer;
someObjectPointer_->getImage(buffer);

which would need

SomeObject::getImage(Glib::RefPtr<Gdk::Pixbuf>& buffer);

[snip]

-- 
Murray Cumming
[EMAIL PROTECTED]
www.murrayc.com
www.openismus.com

_______________________________________________
gtkmm-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gtkmm-list

Reply via email to