Search code examples
cgtk

Freeing memory in a GtkTreeStore


The function gtk_tree_store_clear() does what the documentation says it does: the store is cleared and all lines inside the associated tree view disappear.

Does this function also free the memory that the store used? For example, if the store had 1,000 lines of gchar *, is all that memory freed?


Solution

  • Yes, otherwise everyone using GtkTreeStore (or GtkListStore for that matter) that would be dealing with a major memory leak. :-)

    That's also the reason why you have to pass a list of GTypes to the constructors of those classes: GTK uses them to lookup on how to free them. If you want to know the implementation details: both classes internally use an internal class called GtkTreeDataList which implements this.

    The fact that it also knows about thise GTypes is also the reason why you don't need to explicitly strdup() your strings when passing them one for example: that's also something the subclass will lookup from the respective column types.