FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Deletion

 
Post new topic   Reply to topic     Forum Index -> gtkD
View previous topic :: View next topic  
Author Message
maelp



Joined: 23 Sep 2007
Posts: 12

PostPosted: Fri Jul 04, 2008 9:16 am    Post subject: Deletion Reply with quote

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
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Fri Jul 04, 2008 12:32 pm    Post subject: Re: Deletion Reply with quote

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
View user's profile Send private message
maelp



Joined: 23 Sep 2007
Posts: 12

PostPosted: Fri Jul 04, 2008 4:37 pm    Post subject: Reply with quote

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
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Sat Jul 05, 2008 7:02 am    Post subject: Reply with quote

The following should work in svn r516:

Code:
addOnDestroy( &onDestroy );

void onDestroy( ObjectGtk object )
{
   ....
}
Back to top
View user's profile Send private message
maelp



Joined: 23 Sep 2007
Posts: 12

PostPosted: Sat Jul 05, 2008 8:30 am    Post subject: Reply with quote

It works with r518,
but why is it working with ObjectGtk.onDestroy and not Widget.onDestroy ?
Back to top
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Sun Jul 06, 2008 8:06 am    Post subject: Reply with quote

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
View user's profile Send private message
maelp



Joined: 23 Sep 2007
Posts: 12

PostPosted: Mon Jul 07, 2008 7:51 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> gtkD All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group