Free object/widget in GTK?
I've got a pack box in my GTK application and I'm replacing it every once in a while with a completely new entry (at least for now cause I'm in a hurry).
Since I'm replacing it with a new instance, do I need to explicitly free from memory the old pack box contents or is there some garbage collection in GTK?
If I do need to explicitly need to free the object, is there a command that will recursively go to all objects in that tree (like will it clear my button in a box container in开发者_如何学编程side my main pack box)? Also, what about the signals and handlers connected to the objects?
I'm using C/GTK-2.0 (gcc v4.4.3 and GTK 2.20.0).
GObjects are reference-counted. When you pack a widget into a container, the container takes over ownership.
When you do gtk_container_remove()
, the reference held by the container is dropped, which typically causes the widget to be destroyed.
So no, you shouldn't need to explicitly destroy it, just removing it from the container is enough.
The documentation for the gtk_container_remove()
API also says that it can be more efficient to just call gtk_widget_destroy()
directly on the child, so if that's what you're already doing you're fine.
精彩评论