[gcompris-devel] Re: Question on memory

bruno bruno.coudoin at free.fr
Sun Nov 11 12:39:02 UTC 2001


Pascal wrote:

In clic_on_letter.c I put following code at line 200 :

/* ==================================== */
/* Destroy all the items */
static void clic_on_letter_destroy_all_items()
{
  if(boardRootItem!=NULL)
    gtk_object_destroy (GTK_OBJECT(boardRootItem));

    // Is the following needed ? It seems to segfault
/*  gtk_object_destroy (GTK_OBJECT(l1_item));
  gtk_object_destroy (GTK_OBJECT(l2_item));
  gtk_object_destroy (GTK_OBJECT(l3_item));
  gtk_object_destroy (GTK_OBJECT(l4_item));
  gtk_object_destroy (GTK_OBJECT(button1));
  gtk_object_destroy (GTK_OBJECT(button2));
  gtk_object_destroy (GTK_OBJECT(button3));
  gtk_object_destroy (GTK_OBJECT(button4));
*/
  boardRootItem = NULL;
}

Could anybody tell me if the commented code is needed or not (to avoid
memory leak) ?

------

No, you don't need and more you cannot. Deleting boardRootItem deletes
automatically all its children.
It took me some time to understand this so early gcompris board do not
rely on it and I manage the list of object in a glist.
I already deleted your comment here in the CVS ;)

Bruno.






More information about the Gcompris-devel mailing list