Re: [gtkmm] Method Gtk::Object::destroy_notify_() (in File gtk/gtkmm/object.c c) contains a "delete this"



On Mon, 2002-08-26 at 12:57, Hopfes, Harald wrote:
> Hi!
> 
> I still looking for the cause of bug
> http://bugzilla.gnome.org/show_bug.cgi?id=78578
> and I found the "delete this" statement in gtk/gtkmm/object.cc
> 
> I hope the author of the "delete this" considered the following:
> 
> Your program will crash (or behave strangely) if the object
> - was not created with 'new'; (might _NOT_ be allocated on the heap, but on
> the stack ... which could cause a disaster)
> - is a member of an array created with 'new[]';
> - is later the object of an explicit 'delete';
> - is referenced anyplace after the 'delete', such as by the function which
> invoked the cleaner.
>   Calling the cleaner from another member function would be particularly
> interesting :-)
> 
> Sometimes you can be sure that it is safe to 'delete this'. In general, it
> is dangerous. 

Yes, we have considered that. In Gtk::Object, the delete this is only
called on managed() objects, which would always be created with new. In
Glib::ObjectBase delete this is only used on objects in RefPtrs that can
only be instantiated with a create() method, which uses new().

I think that is quite clear, but feel free to patch to add yet more
comments. By the way, I don't think the potential problems mentioned
above are specific to "delete this", but to "delete" in general.

Have you found that this is the cause of any problem? I do find "delete
this" to be distasteful in general, but these are clearly cases where it
is appropriate.
 
-- 
Murray Cumming
murrayc usa net
www.murrayc.com




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