Hi,
I have the following code, I want to know if the idea is correct.
Calling view_and_model with new_view = TRUE the list is cleared and the new list is created in view_box.
Calling view_and_model with new_view = FALSE the list is cleared from view_box.
Any problems with memory allocation ?
After calling "gtk_widget_destroy( scrolled_win )" all objects are cleared from RAM or not ?
This style code is working in a aplication but I'm not sure about clearing RAM after "gtk_widget_destroy( scrolled_win )".
Thanks !
Code:
GtkWidget *scrolled_win = NULL;
GtkWidget *view;
GtkListStore *store_details;
static void fill( void ) {
.....
}
static void fill_model( void ) {
store_details = gtk_list_store_new( 1, G_TYPE_STRING );
// Inserted code !!!!!
gtk_tree_view_set_model( GTK_TREE_VIEW( view ), GTK_TREE_MODEL( store_details ));
// ----------------
fill();
}
static void view_and_model( GtkWidget *view_box,
gboolean new_view ) {
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
if ( new_view ) {
if ( scrolled_win != NULL ) {
gtk_widget_destroy( scrolled_win );
// Inserted code !!!!
g_object_unref( G_OBJECT( store_details ));
// -----------------
}
view = gtk_tree_view_new();
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes( "col", renderer, "text", 0, NULL );
fill_model();
scrolled_win = gtk_scrolled_window_new( NULL, NULL );
gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scrolled_win ), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
gtk_container_add( GTK_CONTAINER( scrolled_win ), view );
gtk_box_pack_start( GTK_BOX( view_box ), scrolled_win, TRUE, TRUE, 0 );
gtk_tree_view_expand_all( GTK_TREE_VIEW( view ));
gtk_widget_show_all( view_box );
}
if ( !new_view ) {
if ( scrolled_win != NULL ) {
gtk_widget_destroy( scrolled_win );
// Inserted code !!!!
g_object_unref( G_OBJECT( store_details ));
// -----------------
scrolled_win = NULL;
}
}
}