Re: gobject destructor



On 11/05/2004 6:38 AM, Jochen Voss wrote:

Hello,

I use gob to derive a new object class from GtkWindow.
While debugging I found that the call

   gtk_object_destroy (GTK_OBJECT (window));

calls the destroy method of my object twice.

Is this expected behaviour or does this indicate a problem?
In the latter case, what could be wrong?
This is not unexpected behaviour. The "destroy" signal is not the equivalent of a deconstructor (for that, you want "finalize"). Instead, it is used to tell a GtkObject that it should break its references to other objects. This is used to allow reference counting to work in the presence of reference loops (eg. object A holds a reference to object B which in turn holds a reference to object A). If the reference loop isn't broken, then none of the objects in the loop will get finalised.

So if your widget can't handle destroy being called multiple times, then it is a bug in your widget. You probably want to move some of the code you currently have in the "destroy" handler to a "finalize" handler.

James.

--
Email: james daa com au
WWW:   http://www.daa.com.au/~james/





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