开发者

Python and GTK+: How to create garbage collector friendly objects?

I started writing a small application in Python with GTK+ as my widget toolkit开发者_运维百科. Recently I decided to do some memory optimization and noticed that a most of PyGTK objects I create never gets released by garbage collector. This number keeps growing even if I open a window and properly destroy it afterward.

Can someone point me in the right direction on how to create and handle GTK+ objects from Python. Am not using Glade or anything like that.

Also I noticed that creating window like this:

class SomeWindow:
   def __init__(self):
      self.window = gtk.Window(type=gtk.WINDOW_TOPLEVEL)

Instead of:

class SomeWindow(gtk.Window):
   def __init__(self):
      super(SomeWindow, self).__init__(type=gtk.WINDOW_TOPLEVEL)

Gives 2+ objects less in GC list.

Any advices you can give me?


Did you call .destroy()?

According to the gtk.Widget.destroy docu GTK maintains a list of toplevel windows that will keep a reference alive.

And in case you use any Python destructors, they can also prevent cyclic references from being freed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜