problem with memory in gtk_view/model



Hi all,
excuse me for my obstinacy, but it is fundamental for my application.
I wrote on 20. June that I have a problem with memory usage of
gtk_model/view, but nobody take notice from this.
Here is a new running. 
We have an application whith GTK+2.0 and using gtk_tree_view and
gtk_list_model. Because we wont to show records from the database, it is
possible that there can be more then 10000 record. 
The problem is, after every filling/clearing the model/view the usage
memory is continue growing up. And after N fillings/clearing the app
crash because there is now more memory in the system.
I use linux rh 7.2 with 2.4.16 Kernel and gtk+-2.0.5

To find the failure I took a demo and modify the source, so you can see,
how we fill and clear the model. What must we do to clear all memory
when we fill the modell new.

I put the sources of the test and the results in this message:

Tanks for your help.
bernd


Attachment: ergebnisse.gnumeric
Description: Memory usage after filling/clear

#include <gtk/gtk.h>

typedef struct {
  const gchar *string;
  gboolean is_editable;
} ListEntry;

enum {
  STRING_COLUMN,
  IS_EDITABLE_COLUMN,
  NUM_COLUMNS
};

static ListEntry model_strings[] =
{
  {" %d \t A simple string", TRUE },
  {" %d \t Another string!", TRUE },
  {" %d \t Guess what, a third string. This one can't be edited", FALSE },
  {" %d \t And then a fourth string. Neither can this", FALSE },
  {" %d \t Multiline\nFun!", TRUE },
  { NULL }
};

static GtkTreeModel *
create_model (void)
{
  GtkListStore *model;
  
  model = gtk_list_store_new (NUM_COLUMNS,
			      G_TYPE_STRING,
			      G_TYPE_BOOLEAN);
g_print("After Create Modell\n");  
g_mem_profile();
  return GTK_TREE_MODEL (model);
}


/* Our usual callback function */
void fuelle( GtkWidget *widget,
               gpointer   treemodel )
{
	static int zaehler = 1;
	gint i,j;
	GtkTreeIter iter;
	char	puffer[256];
	
	for (j=0; j < 1000; j++){
		for (i = 0; model_strings[i].string != NULL; i++)
		{
			gtk_list_store_append (treemodel, &iter);
			sprintf(puffer, model_strings[i].string, j*100+i);
			gtk_list_store_set (treemodel, &iter,
				  STRING_COLUMN, puffer,
				  IS_EDITABLE_COLUMN, model_strings[i].is_editable,
				  -1);
		}
	} 
g_print("After %d. Fill Modell\n", zaehler++);  
g_mem_profile();
}

/* Our usual callback function */
void leere( GtkWidget *widget,
               gpointer   treemodel )
{
	static int zaehler = 1;
	gtk_list_store_clear (treemodel);
g_print("After %d. Clear Modell\n", zaehler++);  
g_mem_profile();
}


gint
main (gint argc, gchar **argv)
{
	GtkWidget *window;
	GtkWidget *scrolled_window;
	GtkWidget *tree_view;
	GtkWidget *button1;
	GtkWidget *box;
	GtkWidget *bb;
	GtkWidget *button2;
	GtkTreeModel *tree_model;
	GtkCellRenderer *renderer;

	g_mem_set_vtable(glib_mem_profiler_table);

	gtk_init (&argc, &argv);

	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title (GTK_WINDOW (window), "GtkTreeView editing sample");
	gtk_signal_connect (GTK_OBJECT (window), "destroy", gtk_main_quit, NULL);

	/* Create box  */
	box = gtk_vbox_new (FALSE, 0);
	gtk_container_set_border_width (GTK_CONTAINER (box), 2);
	gtk_box_set_homogeneous(GTK_BOX(box), FALSE);
	gtk_container_add (GTK_CONTAINER (window), box);

	scrolled_window = gtk_scrolled_window_new (NULL, NULL);
	gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_ETCHED_IN);
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
	gtk_container_add (GTK_CONTAINER (box), scrolled_window);
	tree_model = create_model ();
	tree_view = gtk_tree_view_new_with_model (tree_model);
	gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree_view), TRUE);
	gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), TRUE);

	renderer = gtk_cell_renderer_text_new ();
	gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
						   -1, "String",
					       renderer,
					       "text", STRING_COLUMN,
					       "editable", IS_EDITABLE_COLUMN,
					       NULL);
	bb = gtk_hbutton_box_new();
 	gtk_container_add (GTK_CONTAINER (box), bb);
   /* Create a new button */
    button1 = gtk_button_new_with_label ("Fuelle");
    /* Connect the "clicked" signal of the button to our callback */
    g_signal_connect (G_OBJECT (button1), "clicked",
		      G_CALLBACK (fuelle), (gpointer) tree_model);
	gtk_container_add (GTK_CONTAINER (bb), button1);
		      
   /* Create a new button */
    button2 = gtk_button_new_with_label ("Leere");
    /* Connect the "clicked" signal of the button to our callback */
	g_signal_connect (G_OBJECT (button2), "clicked",
		  G_CALLBACK (leere), (gpointer) tree_model);
	gtk_container_add (GTK_CONTAINER (bb), button2);



	renderer = gtk_cell_renderer_toggle_new ();

	gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
					   -1, "Editable",
					   renderer,
					   "active", IS_EDITABLE_COLUMN,
					   NULL);

	gtk_container_add (GTK_CONTAINER (scrolled_window), tree_view);

	gtk_window_set_default_size (GTK_WINDOW (window),
				   650, 400);

	gtk_widget_show_all (window);
	gtk_main ();

  return 0;
}


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