Inputs are garbage collected, making MucListTab collectable.

Memory improvement issues.
This commit is contained in:
Florent Le Coz 2011-03-07 21:41:13 +01:00
parent a769babf0a
commit 8f48c5ede7
3 changed files with 34 additions and 14 deletions

View file

@ -1200,12 +1200,15 @@ class Core(object):
if isinstance(tab, tabs.RosterInfoTab) or\ if isinstance(tab, tabs.RosterInfoTab) or\
isinstance(tab, tabs.InfoTab): isinstance(tab, tabs.InfoTab):
return # The tab 0 should NEVER be closed return # The tab 0 should NEVER be closed
del tab.key_func # Remove self references
del tab.commands # and make the object collectable
tab.on_close() tab.on_close()
self.tabs.remove(tab) self.tabs.remove(tab)
self.rotate_rooms_left() import gc
del tab.key_func # Remove self references gc.collect()
del tab.commands # and make the object collectable log.debug('___ Referrers of closing tab:\n%s\n______' % gc.get_referrers(tab))
del tab del tab
self.refresh_window()
def move_separator(self): def move_separator(self):
""" """

View file

@ -61,6 +61,7 @@ class Tab(object):
number = 0 number = 0
tab_core = None tab_core = None
def __init__(self): def __init__(self):
self.input = None
self._color_state = theme.COLOR_TAB_NORMAL self._color_state = theme.COLOR_TAB_NORMAL
self.need_resize = False self.need_resize = False
self.nb = Tab.number self.nb = Tab.number
@ -226,10 +227,10 @@ class Tab(object):
""" """
Called when the tab is to be closed Called when the tab is to be closed
""" """
pass self.input.on_delete()
def __del__(self): def __del__(self):
log.debug('Closing tab %s' % self.__class__.__name__) log.debug('------ Closing tab %s' % self.__class__.__name__)
class ChatTab(Tab): class ChatTab(Tab):
""" """
@ -384,9 +385,6 @@ class InfoTab(ChatTab, TabWithInfoWin):
def just_before_refresh(self): def just_before_refresh(self):
return return
def on_close(self):
return
class MucTab(ChatTab, TabWithInfoWin): class MucTab(ChatTab, TabWithInfoWin):
""" """
The tab containing a multi-user-chat room. The tab containing a multi-user-chat room.
@ -726,9 +724,6 @@ class MucTab(ChatTab, TabWithInfoWin):
def just_before_refresh(self): def just_before_refresh(self):
return return
def on_close(self):
return
def handle_presence(self, presence): def handle_presence(self, presence):
from_nick = presence['from'].resource from_nick = presence['from'].resource
from_room = presence['from'].bare from_room = presence['from'].bare
@ -1036,9 +1031,6 @@ class PrivateTab(ChatTab, TabWithInfoWin):
def just_before_refresh(self): def just_before_refresh(self):
return return
def on_close(self):
return
def rename_user(self, old_nick, new_nick): def rename_user(self, old_nick, new_nick):
""" """
The user changed her nick in the corresponding muc: update the tabs name and The user changed her nick in the corresponding muc: update the tabs name and
@ -1474,6 +1466,7 @@ class ConversationTab(ChatTab, TabWithInfoWin):
return return
def on_close(self): def on_close(self):
Tab.on_close(self)
if config.get('send_chat_states', 'true') == 'true': if config.get('send_chat_states', 'true') == 'true':
self.send_chat_state('gone') self.send_chat_state('gone')
@ -1541,6 +1534,7 @@ class MucListTab(Tab):
self.input.do_command("/") # we add the slash self.input.do_command("/") # we add the slash
def close(self, arg=None): def close(self, arg=None):
self.input.on_delete()
self.core.close_tab(self) self.core.close_tab(self)
def join_selected_no_focus(self): def join_selected_no_focus(self):

View file

@ -734,6 +734,13 @@ class Input(Win):
self.on_input = None # callback called on any key pressed self.on_input = None # callback called on any key pressed
self.color = None # use this color on addstr self.color = None # use this color on addstr
def on_delete(self):
"""
Remove all references kept to a tab, so that the tab
can be garbage collected
"""
del self.key_func
def set_color(self, color): def set_color(self, color):
self.color = color self.color = color
self.rewrite_text() self.rewrite_text()
@ -1171,6 +1178,22 @@ class CommandInput(Input):
self.addstr(0, cursor_pos, '') # WTF, this works but .move() doesn't… self.addstr(0, cursor_pos, '') # WTF, this works but .move() doesn't…
self._refresh() self._refresh()
def on_delete(self):
"""
SERIOUSLY BIG WTF.
I can do
self.key_func.clear()
but not
del self.key_func
because that would raise an AttributeError exception. WTF.
"""
self.on_abort = None
self.on_success = None
self.on_input = None
self.key_func.clear()
class VerticalSeparator(Win): class VerticalSeparator(Win):
""" """
Just a one-column window, with just a line in it, that is Just a one-column window, with just a line in it, that is