Bug 2616. Fixes for memory leaks in person and family editors

svn: r12141
This commit is contained in:
Gary Burton 2009-02-26 21:44:22 +00:00
parent a238e7448f
commit 912e5556e2
3 changed files with 128 additions and 78 deletions

View File

@ -2,7 +2,7 @@
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2000-2007 Donald N. Allingham # Copyright (C) 2000-2007 Donald N. Allingham
# 2009 Gary Burton # Copyright (C) 2009 Gary Burton
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -414,6 +414,8 @@ class EditFamily(EditPrimary):
family, dbstate.db.get_family_from_handle, family, dbstate.db.get_family_from_handle,
dbstate.db.get_family_from_gramps_id) dbstate.db.get_family_from_gramps_id)
self.track_ref_for_deletion("tooltips")
# look for the scenerio of a child and no parents on a new # look for the scenerio of a child and no parents on a new
# family # family
@ -466,10 +468,10 @@ class EditFamily(EditPrimary):
self.obj = self.dbstate.db.get_family_from_handle(self.obj.get_handle()) self.obj = self.dbstate.db.get_family_from_handle(self.obj.get_handle())
self.reload_people() self.reload_people()
self.event_embed.rebuild() self.event_list.rebuild()
self.source_embed.rebuild() self.source_list.rebuild()
self.attr_embed.data = self.obj.get_attribute_list() self.attr_list.data = self.obj.get_attribute_list()
self.attr_embed.rebuild() self.attr_list.rebuild()
self.lds_embed.data = self.obj.get_lds_ord_list() self.lds_embed.data = self.obj.get_lds_ord_list()
self.lds_embed.rebuild() self.lds_embed.rebuild()
@ -497,7 +499,7 @@ class EditFamily(EditPrimary):
mhandle = self.obj.get_mother_handle() mhandle = self.obj.get_mother_handle()
self.update_mother(mhandle) self.update_mother(mhandle)
self.child_list.rebuild() self.child_tab.rebuild()
def get_menu_title(self): def get_menu_title(self):
if self.obj.get_handle(): if self.obj.get_handle():
@ -524,7 +526,6 @@ class EditFamily(EditPrimary):
# FIXME: remove if we can use show() # FIXME: remove if we can use show()
self.window.show_all = self.window.show self.window.show_all = self.window.show
self.fbirth = self.top.get_widget('fbirth') self.fbirth = self.top.get_widget('fbirth')
self.fdeath = self.top.get_widget('fdeath') self.fdeath = self.top.get_widget('fdeath')
self.fbirth_label = self.top.get_widget('label578') self.fbirth_label = self.top.get_widget('label578')
@ -629,38 +630,57 @@ class EditFamily(EditPrimary):
notebook = gtk.Notebook() notebook = gtk.Notebook()
self.child_list = self._add_tab( self.child_list = ChildEmbedList(self.dbstate,
notebook, self.uistate,
ChildEmbedList(self.dbstate,self.uistate, self.track, self.obj)) self.track,
self.obj)
self.child_tab = self._add_tab(notebook, self.child_list)
self.track_ref_for_deletion("child_list")
self.track_ref_for_deletion("child_tab")
self.event_embed = EventEmbedList(self.dbstate, self.uistate, self.event_list = EventEmbedList(self.dbstate,
self.track,self.obj) self.uistate,
self.event_list = self._add_tab(notebook, self.event_embed) self.track,
self.obj)
self._add_tab(notebook, self.event_list)
self.track_ref_for_deletion("event_list")
self.source_embed = SourceEmbedList(self.dbstate, self.uistate, self.source_list = SourceEmbedList(self.dbstate,
self.track, self.obj) self.uistate,
self.src_list = self._add_tab(notebook, self.source_embed) self.track,
self.obj)
self.attr_embed = FamilyAttrEmbedList(self.dbstate, self.uistate, self._add_tab(notebook, self.source_list)
self.track_ref_for_deletion("source_list")
self.attr_list = FamilyAttrEmbedList(self.dbstate,
self.uistate,
self.track, self.track,
self.obj.get_attribute_list()) self.obj.get_attribute_list())
self.attr_list = self._add_tab(notebook, self.attr_embed) self._add_tab(notebook, self.attr_list)
self.track_ref_for_deletion("attr_list")
self.note_tab = self._add_tab( self.note_tab = NoteTab(self.dbstate,
notebook, self.uistate,
NoteTab(self.dbstate, self.uistate, self.track, self.track,
self.obj.get_note_list(), self.get_menu_title(), self.obj.get_note_list(),
notetype=gen.lib.NoteType.FAMILY)) self.get_menu_title(),
notetype=gen.lib.NoteType.FAMILY)
self._add_tab(notebook, self.note_tab)
self.track_ref_for_deletion("note_tab")
self.gallery_tab = self._add_tab( self.gallery_tab = GalleryTab(self.dbstate,
notebook, self.uistate,
GalleryTab(self.dbstate, self.uistate, self.track, self.track,
self.obj.get_media_list())) self.obj.get_media_list())
self._add_tab(notebook, self.gallery_tab)
self.track_ref_for_deletion("gallery_tab")
self.lds_embed = FamilyLdsEmbedList(self.dbstate, self.uistate, self.lds_embed = FamilyLdsEmbedList(self.dbstate,
self.uistate,
self.track, self.track,
self.obj.get_lds_ord_list()) self.obj.get_lds_ord_list())
self.lds_list = self._add_tab(notebook, self.lds_embed) self._add_tab(notebook, self.lds_embed)
self.track_ref_for_deletion("lds_embed")
self._setup_notebook_tabs( notebook) self._setup_notebook_tabs( notebook)
notebook.show_all() notebook.show_all()

View File

@ -2,7 +2,7 @@
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2000-2007 Donald N. Allingham # Copyright (C) 2000-2007 Donald N. Allingham
# 2009 Gary Burton # Copyright (C) 2009 Gary Burton
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -313,66 +313,92 @@ class EditPerson(EditPrimary):
notebook = gtk.Notebook() notebook = gtk.Notebook()
notebook.set_scrollable(True) notebook.set_scrollable(True)
self.event_list = self._add_tab( self.event_list = PersonEventEmbedList(self.dbstate,
notebook, self.uistate,
PersonEventEmbedList(self.dbstate, self.uistate, self.track,
self.track, self.obj)) self.obj)
self._add_tab(notebook, self.event_list)
self.track_ref_for_deletion("event_list")
self.name_list = self._add_tab( self.name_list = NameEmbedList(self.dbstate,
notebook, self.uistate,
NameEmbedList(self.dbstate, self.uistate, self.track, self.track,
self.obj.get_alternate_names(), self.obj, self.obj.get_alternate_names(),
self.name_callback)) self.obj,
self.name_callback)
self._add_tab(notebook, self.name_list)
self.track_ref_for_deletion("name_list")
self.srcref_list = self._add_tab( self.srcref_list = SourceEmbedList(self.dbstate,
notebook, self.uistate,
SourceEmbedList(self.dbstate,self.uistate,self.track,self.obj)) self.track,
self.obj)
self._add_tab(notebook, self.srcref_list)
self.track_ref_for_deletion("srcref_list")
self.attr_list = self._add_tab( self.attr_list = AttrEmbedList(self.dbstate,
notebook, self.uistate,
AttrEmbedList(self.dbstate, self.uistate, self.track, self.track,
self.obj.get_attribute_list())) self.obj.get_attribute_list())
self._add_tab(notebook, self.attr_list)
self.track_ref_for_deletion("attr_list")
self.addr_list = self._add_tab( self.addr_list = AddrEmbedList(self.dbstate,
notebook, self.uistate,
AddrEmbedList(self.dbstate, self.uistate, self.track, self.track,
self.obj.get_address_list())) self.obj.get_address_list())
self._add_tab(notebook, self.addr_list)
self.track_ref_for_deletion("addr_list")
self.note_tab = self._add_tab( self.note_tab = NoteTab(self.dbstate,
notebook, self.uistate,
NoteTab(self.dbstate, self.uistate, self.track, self.track,
self.obj.get_note_list(), self.get_menu_title(), self.obj.get_note_list(),
notetype=gen.lib.NoteType.PERSON)) self.get_menu_title(),
notetype=gen.lib.NoteType.PERSON)
self._add_tab(notebook, self.note_tab)
self.track_ref_for_deletion("note_tab")
self.gallery_tab = self._add_tab( self.gallery_tab = GalleryTab(self.dbstate,
notebook, self.uistate,
GalleryTab(self.dbstate, self.uistate, self.track, self.track,
self.obj.get_media_list(), self.obj.get_media_list(),
self.load_person_image)) self.load_person_image)
self._add_tab(notebook, self.gallery_tab)
self.track_ref_for_deletion("gallery_tab")
self.web_list = self._add_tab( self.web_list = WebEmbedList(self.dbstate,
notebook, self.uistate,
WebEmbedList(self.dbstate, self.uistate, self.track, self.track,
self.obj.get_url_list())) self.obj.get_url_list())
self._add_tab(notebook, self.web_list)
self.track_ref_for_deletion("web_list")
self.person_ref_list = PersonRefEmbedList(self.dbstate, self.uistate, self.person_ref_list = PersonRefEmbedList(self.dbstate, self.uistate,
self.track, self.track,
self.obj.get_person_ref_list()) self.obj.get_person_ref_list())
self.pref_list = self._add_tab(notebook, self.person_ref_list) self._add_tab(notebook, self.person_ref_list)
self.lds_list = self._add_tab( self.track_ref_for_deletion("person_ref_list")
notebook,
LdsEmbedList(self.dbstate, self.uistate, self.track,
self.obj.get_lds_ord_list()))
self.backref_tab = self._add_tab( self.lds_list = LdsEmbedList(self.dbstate,
notebook, self.uistate,
PersonBackRefList(self.dbstate, self.uistate, self.track, self.track,
self.db.find_backlink_handles(self.obj.handle))) self.obj.get_lds_ord_list())
self._add_tab(notebook, self.lds_list)
self.track_ref_for_deletion("lds_list")
self._setup_notebook_tabs( notebook) self.backref_tab = PersonBackRefList(self.dbstate,
self.uistate,
self.track,
self.db.find_backlink_handles(self.obj.handle))
self._add_tab(notebook, self.backref_tab)
self.track_ref_for_deletion("backref_tab")
self._setup_notebook_tabs(notebook)
notebook.show_all() notebook.show_all()
self.top.get_widget('vbox').pack_start(notebook, True) self.top.get_widget('vbox').pack_start(notebook, True)
def _changed_title(self, obj): def _changed_title(self, obj):
""" """
callback to changes typed by user to the person name. callback to changes typed by user to the person name.
@ -509,6 +535,8 @@ class EditPerson(EditPrimary):
""" """
self.all_action = gtk.ActionGroup("/PersonAll") self.all_action = gtk.ActionGroup("/PersonAll")
self.home_action = gtk.ActionGroup("/PersonHome") self.home_action = gtk.ActionGroup("/PersonHome")
self.track_ref_for_deletion("all_action")
self.track_ref_for_deletion("home_action")
self.all_action.add_actions([ self.all_action.add_actions([
('ActivePerson', gtk.STOCK_APPLY, _("Make Active Person"), ('ActivePerson', gtk.STOCK_APPLY, _("Make Active Person"),

View File

@ -467,8 +467,8 @@ class ManagedWindow:
Takes care of closing children and removing itself from menu. Takes care of closing children and removing itself from menu.
""" """
self.clean_up()
self._save_size() self._save_size()
self.clean_up()
self.uistate.gwm.close_track(self.track) self.uistate.gwm.close_track(self.track)
self.opened = False self.opened = False
self.parent_window.present() self.parent_window.present()
@ -515,12 +515,14 @@ class ManagedWindow:
""" """
Remove any instance variables from scope which point to non-glade Remove any instance variables from scope which point to non-glade
GTK objects so that the class can be garbage collected. GTK objects so that the class can be garbage collected.
Run the clean_up method on the object first before removing it. If the object is a Gramps widget then it should have a clean_up method
which can be called that removes any other GTK object it contains.
""" """
while len(self.__refs_for_deletion): while len(self.__refs_for_deletion):
attr = self.__refs_for_deletion.pop() attr = self.__refs_for_deletion.pop()
obj = getattr(self, attr) obj = getattr(self, attr)
obj.clean_up() if hasattr(obj, 'clean_up'):
obj.clean_up()
delattr(self, attr) delattr(self, attr)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #