Free GTK object / widget?

I have a package in my GTK application and I replace it every time again with a completely new entry (at least right now I'm in a hurry).

Since I am replacing it with a new instance, do I need to explicitly free the contents of the old package from memory, or is there any garbage collection in GTK?

If I need to explicitly free an object, is there a command that will recursively jump to all the objects in this tree (for example, will clear my button in the box container inside my main package)? Also, what about signals and handlers associated with objects?

I am using C / GTK-2.0 (gcc v4.4.3 and GTK 2.20.0).

+3
source share
1 answer

GObjects are counted by reference. When you pack the widget in a container, the container becomes the property.

When you execute gtk_container_remove() , the link contained in the container is dropped, which usually leads to the destruction of the widget.

No, you do not need to explicitly destroy it, just remove it from the container.

The documentation for the gtk_container_remove() API also says that it is more efficient to just call gtk_widget_destroy() directly on the child, so if this is what you are already doing, everything is fine.

+5
source

Source: https://habr.com/ru/post/1403328/


All Articles