pythontreeviewgtk3treemodel

Should I 'destroy' a liststore (model of treeview) when destroy treeview?


I'm programming python + Gtk3.

I have a Gtk.TreeView with a Gtk.ListStore as model.

At some point of the program I need to destroy the treeview in order to put a fresh one on it's place.

However I don't know what happens with the model. Should I destroy it, clear it, or just leve it there and let python to eat it?

I've also thinked in recycle the same model to the new treeview, but I'd prefer not: too much trouble...

Thanks!


Solution

  • You can leave it to Python's garbage collector, the same way it would go if you'd close the application (it will call g_object_unref on both).

    That said, remember that the idea behind the separation of models and views, is that you can mix them the way you like, i.e. display the same model in different views or even alternatively displaying different models in the same view. That you need to replace both may indicate problems in the way you are designing your UI.