Thread: GtkTreeView memory management question
hi,
have searched on net answer question me haven't had luck yet. hoping fine people here give me hand.
let me preface saying while know c new linux (and gtk) development. have followed tutorials can't seem nail down memory leak coming from. have 2 functions addrow , clearrows defined below:
/* adds row of dummy data filling each column element string */
void addrow{
//create iter add data from
gtktreeiter iter;
//the treeview store
gtkliststore *store = null;
//grab copy of existing store (if 1 exists)
store = (gtkliststore *)gtk_tree_view_get_model((gtktreeview *)mytreeview);
if(store == null)
{
//create gtype array number of columns want
gtype *types = g_new0(gtype, numcols);
//set of types string
for(int i=0; i<numcols; i++)
types[i] = g_type_string;
//create new store of above types
store = gtk_list_store_newv(numcols,types);
//free memory used gtypes
free(types);
}else
g_object_ref(store);
//configure iter append model
gtk_list_store_append(store, &iter);
//loop through array , populate columns
for(int i=0; i<numcols;i++)
{
gtk_list_store_set(store, &iter,i,"dummy data",-1);
}
//set model of treeview display new data
gtk_tree_view_set_model(gtk_tree_view(mytreeview), gtk_tree_model(store));
//free reference
g_object_unref(store);
}
/* rid of rows tree view */
void clearrows{
//grab copy of existing store (if 1 exists)
gtkliststore *store = (gtkliststore *)gtk_tree_view_get_model((gtktreeview *)mytreeview);
if(store != null)
{
gtk_list_store_clear(store);
}
}
when run above functions in loop this
/* test adding 1,000 rows , removing them see if leak memory */
void testaddandremove{
for(int i=0;i<1000;i++)
addrow();
clearrows();
}
memory increases never released. must missing simple. suggest fix or clue me in on problem is?
lot!
Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk GtkTreeView memory management question
Ubuntu
Comments
Post a Comment