4352: more memory leak problems

Fix some memory leak problems in guioptions


svn: r16521
This commit is contained in:
Benny Malengier 2011-01-31 20:39:41 +00:00
parent 070e9ef707
commit 2d052d69cf
2 changed files with 83 additions and 8 deletions

View File

@ -173,7 +173,7 @@ class GuiStringOption(gtk.Entry):
self.connect('changed', self.__text_changed) self.connect('changed', self.__text_changed)
self.set_tooltip_text(self.__option.get_help()) self.set_tooltip_text(self.__option.get_help())
self.__option.connect('avail-changed', self.__update_avail) self.conkey = self.__option.connect('avail-changed', self.__update_avail)
self.__update_avail() self.__update_avail()
def __text_changed(self, obj): # IGNORE:W0613 - obj is unused def __text_changed(self, obj): # IGNORE:W0613 - obj is unused
@ -189,6 +189,13 @@ class GuiStringOption(gtk.Entry):
avail = self.__option.get_available() avail = self.__option.get_available()
self.set_sensitive(avail) self.set_sensitive(avail)
def clean_up(self):
"""
remove stuff that blocks garbage collection
"""
self.__option.disconnect(self.conkey)
self.__option = None
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# GuiColorOption class # GuiColorOption class
@ -248,7 +255,7 @@ class GuiNumberOption(gtk.SpinButton):
self.connect('value_changed', self.__value_changed) self.connect('value_changed', self.__value_changed)
self.set_tooltip_text(self.__option.get_help()) self.set_tooltip_text(self.__option.get_help())
self.__option.connect('avail-changed', self.__update_avail) self.conkey = self.__option.connect('avail-changed', self.__update_avail)
self.__update_avail() self.__update_avail()
def __value_changed(self, obj): # IGNORE:W0613 - obj is unused def __value_changed(self, obj): # IGNORE:W0613 - obj is unused
@ -265,6 +272,13 @@ class GuiNumberOption(gtk.SpinButton):
avail = self.__option.get_available() avail = self.__option.get_available()
self.set_sensitive(avail) self.set_sensitive(avail)
def clean_up(self):
"""
remove stuff that blocks garbage collection
"""
self.__option.disconnect(self.conkey)
self.__option = None
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# GuiTextOption class # GuiTextOption class
@ -293,7 +307,7 @@ class GuiTextOption(gtk.ScrolledWindow):
gtext.set_tooltip_text(self.__option.get_help()) gtext.set_tooltip_text(self.__option.get_help())
self.__buff = gtext.get_buffer() self.__buff = gtext.get_buffer()
self.__buff.connect('changed', self.__value_changed) self.bufcon = self.__buff.connect('changed', self.__value_changed)
def __value_changed(self, obj): # IGNORE:W0613 - obj is unused def __value_changed(self, obj): # IGNORE:W0613 - obj is unused
""" """
@ -303,6 +317,14 @@ class GuiTextOption(gtk.ScrolledWindow):
self.__buff.get_end_iter(), self.__buff.get_end_iter(),
False) ) False) )
self.__option.set_value( text_val.split('\n') ) self.__option.set_value( text_val.split('\n') )
def clean_up(self):
"""
remove stuff that blocks garbage collection
"""
self.__option = None
self.__buff.disconnect(self.bufcon)
self.__buff = None
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -320,7 +342,7 @@ class GuiBooleanOption(gtk.CheckButton):
self.connect('toggled', self.__value_changed) self.connect('toggled', self.__value_changed)
self.set_tooltip_text(self.__option.get_help()) self.set_tooltip_text(self.__option.get_help())
self.__option.connect('avail-changed', self.__update_avail) self.conkey = self.__option.connect('avail-changed', self.__update_avail)
self.__update_avail() self.__update_avail()
def __value_changed(self, obj): # IGNORE:W0613 - obj is unused def __value_changed(self, obj): # IGNORE:W0613 - obj is unused
@ -336,6 +358,13 @@ class GuiBooleanOption(gtk.CheckButton):
avail = self.__option.get_available() avail = self.__option.get_available()
self.set_sensitive(avail) self.set_sensitive(avail)
def clean_up(self):
"""
remove stuff that blocks garbage collection
"""
self.__option.disconnect(self.conkey)
self.__option = None
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# GuiEnumeratedListOption class # GuiEnumeratedListOption class
@ -359,8 +388,8 @@ class GuiEnumeratedListOption(gtk.HBox):
self.set_tooltip_text(self.__option.get_help()) self.set_tooltip_text(self.__option.get_help())
self.__combo.connect('changed', self.__value_changed) self.__combo.connect('changed', self.__value_changed)
self.__option.connect('options-changed', self.__update_options) self.conkey1 = self.__option.connect('options-changed', self.__update_options)
self.__option.connect('avail-changed', self.__update_avail) self.conkey2 = self.__option.connect('avail-changed', self.__update_avail)
self.__update_avail() self.__update_avail()
def __value_changed(self, obj): # IGNORE:W0613 - obj is unused def __value_changed(self, obj): # IGNORE:W0613 - obj is unused
@ -400,6 +429,14 @@ class GuiEnumeratedListOption(gtk.HBox):
avail = self.__option.get_available() avail = self.__option.get_available()
self.set_sensitive(avail) self.set_sensitive(avail)
def clean_up(self):
"""
remove stuff that blocks garbage collection
"""
self.__option.disconnect(self.conkey1)
self.__option.disconnect(self.conkey2)
self.__option = None
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# GuiPersonOption class # GuiPersonOption class
@ -443,7 +480,7 @@ class GuiPersonOption(gtk.HBox):
pevt.set_tooltip_text(self.__option.get_help()) pevt.set_tooltip_text(self.__option.get_help())
person_button.set_tooltip_text(_('Select a different person')) person_button.set_tooltip_text(_('Select a different person'))
self.__option.connect('avail-changed', self.__update_avail) self.conkey = self.__option.connect('avail-changed', self.__update_avail)
self.__update_avail() self.__update_avail()
def __get_person_clicked(self, obj): # IGNORE:W0613 - obj is unused def __get_person_clicked(self, obj): # IGNORE:W0613 - obj is unused
@ -492,6 +529,13 @@ class GuiPersonOption(gtk.HBox):
""" """
avail = self.__option.get_available() avail = self.__option.get_available()
self.set_sensitive(avail) self.set_sensitive(avail)
def clean_up(self):
"""
remove stuff that blocks garbage collection
"""
self.__option.disconnect(self.conkey)
self.__option = None
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #

View File

@ -97,7 +97,30 @@ class ReportDialog(ManagedWindow.ManagedWindow):
self.init_options(option_class) self.init_options(option_class)
self.init_interface() self.init_interface()
def close(self, *obj):
"""
Close itself.
cleanup things that can prevent garbage collection
"""
totwidg = range(len(self.widgets))
totwidg.reverse()
for ind in totwidg:
if hasattr(self.widgets[ind][1], 'clean_up'):
self.widgets[ind][1].clean_up()
del self.widgets[ind]
delattr(self, 'widgets')
for name, fram in self.frames.iteritems():
totwidg = range(len(fram))
totwidg.reverse()
for ind in totwidg:
if hasattr(fram[ind][1], 'clean_up'):
fram[ind][1].clean_up()
del fram[ind]
self.frames.clear()
self.frames = None
ManagedWindow.ManagedWindow.close(self, *obj)
def init_options(self, option_class): def init_options(self, option_class):
try: try:
if (issubclass(option_class, object) or # New-style class if (issubclass(option_class, object) or # New-style class
@ -657,3 +680,11 @@ def report(dbstate, uistate, person, report_class, options_class,
#just stop, in ManagedWindow, delete-event is already coupled to #just stop, in ManagedWindow, delete-event is already coupled to
#correct action. #correct action.
break break
#do needed cleanup
dialog.db = None
dialog.options = None
if hasattr(dialog, 'window'):
delattr(dialog, 'window')
if hasattr(dialog, 'notebook'):
delattr(dialog, 'notebook')
del dialog