Gtk.Widget.destroy() 在 Python 上有必要吗?

Gtk.Widget.destroy() is necessary on Python?

在阅读关于 GtkBuilder 的 documentation 时,我看到了这段话:

A Gtk.Builder holds a reference to all objects that it has constructed and drops these references when it is finalized. This finalization can cause the destruction of non-widget objects or widgets which are not contained in a toplevel window. For toplevel windows constructed by a builder, it is the responsibility of the user to call Gtk.Widget.destroy() to get rid of them and all the widgets they contain.

但这也适用于 python?那就是当我加载一个顶级window我必须手动销毁它?

嗯,有点。您通常不必手动调用 window 上的 destroy(),因为它会在用户单击 window 的关闭按钮时自动发生。

从来没有必要。但是小部件的销毁与内存管理无关,或者至少不是主要的。它主要是 GUI 模型中存在的问题。如果您将小部件添加到容器中,它会保留在那里直到被销毁。即使你隐藏它,它仍然存在。它可以响应信号,是列表的一部分或其他任何东西。