View previous topic :: View next topic |
Author |
Message |
maelp
Joined: 23 Sep 2007 Posts: 12
|
Posted: Fri Jul 04, 2008 9:16 am Post subject: Deletion |
|
|
Hello,
can you tell me quickly what is the difference between Gtk delete / destroy, and how these mechanisms are embedded in the D bindings (particularly : what is the relation between a widget being destroyed and it's D object being deleted ?).
What is the proper way to handle deletion of Gtk-widgets-as-D-objects ? ie. I write a class
MyOwnWidget : Widget
{
...
}
suppose I have to free some resources when the widget is no longer in use, should I free those resources in the onDestroy / onDelete delegate ? Or in the ~this delegate ? What will happen if I put my widget in a HPaned widget, and I delete/destroy the GTK HPaned widget ? Or if I delete the HPaned D object ?
thanks ! |
|
Back to top |
|
|
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Fri Jul 04, 2008 12:32 pm Post subject: Re: Deletion |
|
|
maelp wrote: | Hello,
can you tell me quickly what is the difference between Gtk delete / destroy, and how these mechanisms are embedded in the D bindings (particularly : what is the relation between a widget being destroyed and it's D object being deleted ?). |
If the D object is deleted the widget won't be destroyed. And if a widget gets destroyed the Garbage collector is free to collect the D object.
Quote: | What is the proper way to handle deletion of Gtk-widgets-as-D-objects ? ie. I write a class
MyOwnWidget : Widget
{
...
}
suppose I have to free some resources when the widget is no longer in use, should I free those resources in the onDestroy / onDelete delegate ? Or in the ~this delegate ? What will happen if I put my widget in a HPaned widget, and I delete/destroy the GTK HPaned widget ? Or if I delete the HPaned D object ? |
With the garbage collector you can't really depend on the destructor, so i would use the onDestroy delegate. |
|
Back to top |
|
|
maelp
Joined: 23 Sep 2007 Posts: 12
|
Posted: Fri Jul 04, 2008 4:37 pm Post subject: |
|
|
I tried adding
addOnDestroy( &onDestroy );
protected int
onDestroy( ... )
{
...
}
to some widgets,
and then calling
myWidget.destroy();
but it looks like the destroy method is not called,
is there something I'm not doing, when defining
the callback? |
|
Back to top |
|
|
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Sat Jul 05, 2008 7:02 am Post subject: |
|
|
The following should work in svn r516:
Code: | addOnDestroy( &onDestroy );
void onDestroy( ObjectGtk object )
{
....
} |
|
|
Back to top |
|
|
maelp
Joined: 23 Sep 2007 Posts: 12
|
Posted: Sat Jul 05, 2008 8:30 am Post subject: |
|
|
It works with r518,
but why is it working with ObjectGtk.onDestroy and not Widget.onDestroy ? |
|
Back to top |
|
|
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Sun Jul 06, 2008 8:06 am Post subject: |
|
|
From the gtk docs for GtkWidget:
Quote: | The ::destroy-event signal is emitted when a GdkWindow is destroyed. You rarely get this signal, because most widgets disconnect themselves from their window before they destroy it, so no widget owns the window at destroy time. |
While the GtkObject destroy event:
Quote: | Signals that all holders of a reference to the GtkObject should release the reference that they hold. May result in finalization of the object if all references are released. |
|
|
Back to top |
|
|
maelp
Joined: 23 Sep 2007 Posts: 12
|
Posted: Mon Jul 07, 2008 7:51 am Post subject: |
|
|
Okay thanks,
I read that, but since many GTK+ tuts on the
internet show widgets and connect their destroy_event signal to
a callback, I was wondering why this wouldn't be called most of the time... maybe it's just for "window"-like widgets ?
Anyway, ObjectGtk.onDestroy works perfectly,
thanks |
|
Back to top |
|
|
|