[pygtk] Statusbar memory leak?
Tony Nelson
tonynelson at georgeanelson.com
Wed Jan 10 02:13:44 WST 2007
Does the statusbar (in pygtk 2.10.3 gtk 2.10.4 python 2.4.4 FC6) leak
memory? I didn't see anything in pygtk's bugzilla.
I have an application that leaks memory when it uses its statusbar, as
viewed in top on linux. It changes the message by popping the top message
and then pushing the new one. I've made a simpler app to demonstrate the
problem. The original app uses the statusbar in a loop that included a
check for gtk.events_pending() / gtk.main_iteration(), while the test
program uses the statusbar in gobject timer. Garbage collection does not
help. All that is needed to leak memory is to call statusbar.pop(),
without calling statusbar.push(), as shown below.
#!/usr/bin/env python
# -*- coding: utf-8; tab-width: 4; indent-tabs-mode: nil -*-
'''statusbar uses up memory.'''
import sys
import pygtk
if not hasattr(sys, 'frozen'):
pygtk.require('2.0')
import gtk
if gtk.gtk_version[0] == 2 and gtk.gtk_version[1] < 4:
sys.exit(_("""%s: gtk version 2.4 required""") % us)
import gobject
import gc
class Wind(gtk.Window):
def __init__(self):
gtk.Window.__init__(self)
self.connect('destroy', lambda wid: gtk.main_quit())
self.set_border_width(2)
self.set_default_size(200, 20)
self.statusbar = sb = gtk.Statusbar()
self.add(sb)
sb.show()
sb.console_context = sb.get_context_id('console_message')
sb.push(sb.console_context, 'Hi')
self.show()
self.count = 0
gobject.timeout_add( 1, lambda self=self: self.do() )
def do(self):
self.count += 1
msg = '''Some test string %d''' % (self.count,)
sb = self.statusbar
sb.pop(sb.console_context)
#sb.push(sb.console_context, msg)
#if 0 == self.count % 10000:
# gc.collect()
#return True
if __name__ == '__main__':
w = Wind()
gtk.main()
--
____________________________________________________________________
TonyN.:' <mailto:tonynelson at georgeanelson.com>
' <http://www.georgeanelson.com/>
More information about the pygtk
mailing list