Memory dealocation using "destroy" signal /callback
- From: Toni Moreno Giménez <toni moreno gimenez wanadoo es>
- To: gtk-list gnome org
- Subject: Memory dealocation using "destroy" signal /callback
- Date: Mon, 20 May 2002 04:03:43 +0200
Hi.
I'm building my own wdgets, most of them , uses dinamic allocated memory and
I need to make sure that this memory is deallocated when the widtget is
destroyed.
I would like to know what is best. replace the GtkObject destroy function or
use a signal conecting "destroy" GtkObject Widget.
Anyway I need to know about the destroy process.
I can understand who make the call to the destroy function.
I have tested this code, drawing my new widget.
but de destroy funcion on my widget seems to be never called.
is the main loop who make the (GtkObject* (myobject))->destroy ??
-MIWIDGET.C--(Using Signal)--------------------------
.....
void my_destroy_func(GtkObject *ob,gpointer data)
{
g_free(MY_WIDGET(ob)->any_data);
printf("data have been destroyed");
}
....
void my_widget_init(MiWidget *mywid)
{
.....
gtk_signal_connect(GTK_OBJECT(mywid),"destroy",GTK_SIGNAL_FUNC(my_destroy_fun
c),NULL);
}
......
.----MYWIDGET.C --(Using callback)---------------------
void my_destroy_func(GtkObject *ob,gpointer data)
{
g_free(MY_WIDGET(ob)->any_data);
printf("data have been destroyed");
}
....
void my_widget_class_init(MiWidgetClass *mywidk)
{
GtkObjectClass *klass=(GtkObjectClass*)mywidk;
klass->destroy=my_destroy_func;
.....
}
....
--MAIN.C------------------------------------------
gint Delete(GtkWidget *widget,gpointer *data)
{
gtk_main_quit();
}
int main (int argc,char *argv[])
{
GtkWidget *window,*wid;
/*GTK Initialization */
gtk_init(&argc,&argv);
/*creating a window*/
window=gtk_window_new(GTK_WINDOW_DIALOG);
gtk_window_set_title(GTK_WINDOW(window),"test");
gtk_signal_connect(GTK_OBJECT(window),
"delete_event",
GTK_SIGNAL_FUNC(Delete),NULL);
wid=my_own_widget_new();
gtk_container_add(GTK_CONTAINER(window), wid);
/*showing all */
gtk_widget_show(skin);
gtk_widget_show(window);
gtk_main();
}
-------------------------------------
In any case, memory are not deallocated. what I'm doing wrong ?
Thaks in advance.
--
=================
Toni Moreno Giménez
=================
Pje de las rosas nº 22
Vilassar de Mar
(Barcelona) España
CP: 08340
-----------------
Tel:937598149
Tel: 699706656
-----------------
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]