dealloc memory



Hi,

In my app there are 3 elements/pointers (elem) saved on:

GPtrArray *array;

With:

g_ptr_array_add (array, (gpointer) elem);

"elem" is defined like this:

struct _elem_struct
{
	GtkWidget *scrolledwindow;
	GtkWidget *view;
	GtkListStore *table;
};

typedef struct _elem_struct elem_struct;

elem_struct elem;

And allocated by:

elem = g_new0 (elem_struct, 1);
new_elem(elem);

.....
.....

void
new_elem (elem_struct *elem)
{
  GtkTreeSelection *selection;
  GtkCellRenderer *cell;
  GtkTreeViewColumn *column;

  /* scrolled window */

  elem->scrolledwindow = gtk_scrolled_window_new (NULL, NULL);

  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (elem->scrolledwindow),
				  GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (elem->scrolledwindow),
				       GTK_SHADOW_OUT);

  elem->view = gtk_tree_view_new ();
  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (elem->view));

  gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
  elem->table = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);

  gtk_tree_view_set_model (GTK_TREE_VIEW (elem->view), GTK_TREE_MODEL (elem->table));

  cell = gtk_cell_renderer_text_new ();
  column = gtk_tree_view_column_new_with_attributes("Header Title", cell,
"text", i, NULL);
  gtk_tree_view_column_set_resizable(GTK_TREE_VIEW_COLUMN(column), TRUE);
  gtk_tree_view_append_column(GTK_TREE_VIEW(elem->view), column);

  gtk_widget_show (elem->view);
  gtk_container_add (GTK_CONTAINER (elem->scrolledwindow), elem->view);

}


1) When program is closed, it deallocates memory like this:

for (i=0; i < 3; i++)  g_free (g_ptr_array_index(array, i));
g_ptr_array_free (array,FALSE);

Is it enough to dealloc memory?
(I got SEGFAULT).


2) When it's used g_ptr_array_remove_index(elem,i) array->len is automatically
updated (it seems not)?

Thanks
France

__________________________________________________________________
Social price: l'ADSL diventa per tutti
Tiscali ADSL Senza Canone 640Kbps: GRATIS fino al 15 aprile costo
di adesione, attivazione e il modem per tutto il 2004. E per i primi 3 mesi,
con il Tiscali social price, navighi a 1,5 euro l'ora! Affrettati!
http://point.tiscali.it/adsl/prodotti/640Kbps/






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