免费对象/部件在GTK? [英] Free object/widget in GTK?

查看:215
本文介绍了免费对象/部件在GTK?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包装盒在我的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).

由于我有一个新的实例替换它,我需要明确地释放内存中的旧包装盒的内容还是有一些垃圾收集GTK?

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 inside my main pack box)? Also, what about the signals and handlers connected to the objects?

我使用C / GTK-2.0(GCC v4.4.3和GTK 2.20.0)。

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

推荐答案

GObjects是引用计数。当你收拾一个小部件放入容器,容器接管所有权。

GObjects are reference-counted. When you pack a widget into a container, the container takes over ownership.

当你做 gtk_container_remove(),由容器保持的参考被丢弃,这会造成小部件被销毁。

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.

借助文档 gtk_container_remove() API还表示,它可以更有效地只是调用 gtk_widget_destroy(),所以如果这是什么你已经做你的罚款。

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.

这篇关于免费对象/部件在GTK?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆