Fix some memory leaks, some still remain.

svn: r21286
This commit is contained in:
Gary Burton 2013-02-03 17:48:36 +00:00
parent 6154ebad23
commit 7004ce9033

View File

@ -745,6 +745,15 @@ class Lexer(object):
else:
self.current_list.insert(0, data)
def clean_up(self):
"""
Break circular references to parsing methods stored in dictionaries
to aid garbage collection
"""
for key in (self.func_map.keys()):
del self.func_map[key]
del self.func_map
#-----------------------------------------------------------------------
#
# GedLine - represents a tokenized version of a GEDCOM line
@ -1795,6 +1804,7 @@ class GedcomParser(UpdateCallback):
self.gedmap = GedcomInfoDB()
self.gedsource = self.gedmap.get_from_source_tag('GEDCOM 5.5')
self.use_def_src = default_source
self.func_list = []
if self.use_def_src:
self.def_src = gen.lib.Source()
fname = os.path.basename(filename).split('\\')[-1]
@ -1864,6 +1874,7 @@ class GedcomParser(UpdateCallback):
# +1 <<CHANGE_DATE>>
TOKEN_CHAN : self.__repo_chan,
}
self.func_list.append(self.subm_parse_tbl)
#
# Parse table for <<INDIVIDUAL_RECORD>> below the level 0 INDI tag
@ -1956,6 +1967,7 @@ class GedcomParser(UpdateCallback):
TOKEN__TODO : self.__skip_record,
TOKEN_TITL : self.__person_titl,
}
self.func_list.append(self.indi_parse_tbl)
self.name_parse_tbl = {
# +1 NPFX <NAME_PIECE_PREFIX> {0:1}
@ -1991,6 +2003,7 @@ class GedcomParser(UpdateCallback):
# found in Brother's keeper.
TOKEN__ADPN : self.__name_adpn,
}
self.func_list.append(self.name_parse_tbl)
#
# Parse table for <<REPOSITORY_RECORD>> below the level 0 REPO tag
@ -2015,6 +2028,7 @@ class GedcomParser(UpdateCallback):
TOKEN_EMAIL : self.__repo_email,
TOKEN_WWW : self.__repo_www,
}
self.func_list.append(self.repo_parse_tbl)
self.event_parse_tbl = {
# n TYPE <EVENT_DESCRIPTOR> {0:1}
@ -2064,6 +2078,7 @@ class GedcomParser(UpdateCallback):
TOKEN_EMAIL : self.__event_email, # FTB for RESI events
TOKEN_WWW : self.__event_www, # FTB for RESI events
}
self.func_list.append(self.event_parse_tbl)
self.adopt_parse_tbl = {
TOKEN_TYPE : self.__event_type,
@ -2093,6 +2108,7 @@ class GedcomParser(UpdateCallback):
TOKEN_CHAN : self.__ignore,
TOKEN_QUAY : self.__ignore,
}
self.func_list.append(self.adopt_parse_tbl)
self.famc_parse_tbl = {
# n FAMC @<XREF:FAM>@ {1:1}
@ -2107,6 +2123,7 @@ class GedcomParser(UpdateCallback):
# GEDit
TOKEN_STAT : self.__ignore,
}
self.func_list.append(self.famc_parse_tbl)
self.person_fact_parse_tbl = {
TOKEN_TYPE : self.__person_fact_type,
@ -2114,6 +2131,7 @@ class GedcomParser(UpdateCallback):
TOKEN_NOTE : self.__person_attr_note,
TOKEN_RNOTE : self.__person_attr_note,
}
self.func_list.append(self.person_fact_parse_tbl)
self.person_attr_parse_tbl = {
TOKEN_TYPE : self.__person_attr_type,
@ -2130,6 +2148,7 @@ class GedcomParser(UpdateCallback):
TOKEN_NOTE : self.__person_attr_note,
TOKEN_RNOTE : self.__person_attr_note,
}
self.func_list.append(self.person_attr_parse_tbl)
self.lds_parse_tbl = {
TOKEN_TEMP : self.__lds_temple,
@ -2142,6 +2161,7 @@ class GedcomParser(UpdateCallback):
TOKEN_RNOTE : self.__lds_note,
TOKEN_STAT : self.__lds_stat,
}
self.func_list.append(self.lds_parse_tbl)
self.asso_parse_tbl = {
TOKEN_RELA : self.__person_asso_rela,
@ -2149,6 +2169,7 @@ class GedcomParser(UpdateCallback):
TOKEN_NOTE : self.__person_asso_note,
TOKEN_RNOTE : self.__person_asso_note,
}
self.func_list.append(self.asso_parse_tbl)
self.citation_parse_tbl = {
TOKEN_PAGE : self.__citation_page,
@ -2164,6 +2185,7 @@ class GedcomParser(UpdateCallback):
TOKEN_RNOTE : self.__citation_note,
TOKEN_TEXT : self.__citation_data_text,
}
self.func_list.append(self.citation_parse_tbl)
self.object_parse_tbl = {
TOKEN_FORM : self.__object_ref_form,
@ -2173,6 +2195,7 @@ class GedcomParser(UpdateCallback):
TOKEN_RNOTE : self.__object_ref_note,
TOKEN_IGNORE : self.__ignore,
}
self.func_list.append(self.object_parse_tbl)
self.parse_loc_tbl = {
TOKEN_ADDR : self.__location_addr,
@ -2190,6 +2213,7 @@ class GedcomParser(UpdateCallback):
TOKEN_PHON : self.__ignore,
TOKEN_IGNORE : self.__ignore,
}
self.func_list.append(self.parse_loc_tbl)
#
# Parse table for <<FAM_RECORD>> below the level 0 FAM tag
@ -2245,6 +2269,7 @@ class GedcomParser(UpdateCallback):
TOKEN_SUBM : self.__ignore,
TOKEN_ATTR : self.__family_attr,
}
self.func_list.append(self.family_func)
self.family_rel_tbl = {
TOKEN__FREL : self.__family_frel,
@ -2252,6 +2277,7 @@ class GedcomParser(UpdateCallback):
TOKEN_ADOP : self.__family_adopt,
TOKEN__STAT : self.__family_stat,
}
self.func_list.append(self.family_rel_tbl)
#
# Parse table for <<SOURCE_RECORD>> below the level 0 SOUR tag
@ -2305,6 +2331,7 @@ class GedcomParser(UpdateCallback):
TOKEN_DATE : self.__ignore,
TOKEN_IGNORE : self.__ignore,
}
self.func_list.append(self.source_func)
#
# Parse table for <<MULTIMEDIA_RECORD>> below the level 0 OBJE tag
@ -2333,6 +2360,7 @@ class GedcomParser(UpdateCallback):
TOKEN_RIN : self.__obje_rin,
TOKEN_CHAN : self.__obje_chan,
}
self.func_list.append(self.obje_func)
self.parse_addr_tbl = {
TOKEN_DATE : self.__address_date,
@ -2352,10 +2380,12 @@ class GedcomParser(UpdateCallback):
TOKEN_TYPE : self.__ignore,
TOKEN_CAUS : self.__ignore,
}
self.func_list.append(self.parse_addr_tbl)
self.event_cause_tbl = {
TOKEN_SOUR : self.__event_cause_source,
}
self.func_list.append(self.event_cause_tbl)
self.event_place_map = {
TOKEN_NOTE : self.__event_place_note,
@ -2369,11 +2399,13 @@ class GedcomParser(UpdateCallback):
# Not legal, but generated by Ultimate Family Tree
TOKEN_QUAY : self.__ignore,
}
self.func_list.append(self.event_place_map)
self.place_map_tbl = {
TOKEN_LATI : self.__place_lati,
TOKEN_LONG : self.__place_long,
}
self.func_list.append(self.place_map_tbl)
self.repo_ref_tbl = {
TOKEN_CALN : self.__repo_ref_call,
@ -2382,15 +2414,18 @@ class GedcomParser(UpdateCallback):
TOKEN_MEDI : self.__repo_ref_medi,
TOKEN_IGNORE : self.__ignore,
}
self.func_list.append(self.repo_ref_tbl)
self.parse_person_adopt = {
TOKEN_ADOP : self.__person_adopt_famc_adopt,
}
self.func_list.append(self.parse_person_adopt)
self.opt_note_tbl = {
TOKEN_RNOTE : self.__optional_note,
TOKEN_NOTE : self.__optional_note,
}
self.func_list.append(self.opt_note_tbl)
self.citation_data_tbl = {
TOKEN_DATE : self.__citation_data_date,
@ -2398,10 +2433,12 @@ class GedcomParser(UpdateCallback):
TOKEN_RNOTE : self.__citation_data_note,
TOKEN_NOTE : self.__citation_data_note,
}
self.func_list.append(self.citation_data_tbl)
self.citation_even_tbl = {
TOKEN_ROLE : self.__citation_even_role,
}
self.func_list.append(self.citation_even_tbl)
#
# Parse table for <<HEADER>> record below the level 0 HEAD tag
@ -2457,6 +2494,7 @@ class GedcomParser(UpdateCallback):
TOKEN_DATE : self.__header_date,
TOKEN_NOTE : self.__header_note,
}
self.func_list.append(self.head_parse_tbl)
self.header_sour_parse_tbl = {
TOKEN_VERS : self.__header_sour_vers,
@ -2464,24 +2502,29 @@ class GedcomParser(UpdateCallback):
TOKEN_CORP : self.__header_sour_corp,
TOKEN_DATA : self.__header_sour_data,
}
self.func_list.append(self.header_sour_parse_tbl)
self.header_sour_data = {
TOKEN_DATE : self.__header_sour_date,
TOKEN_COPR : self.__header_sour_copr,
}
self.func_list.append(self.header_sour_data)
self.header_corp_addr = {
TOKEN_ADDR : self.__repo_addr,
TOKEN_PHON : self.__repo_phon,
}
self.func_list.append(self.header_corp_addr)
self.header_subm = {
TOKEN_NAME : self.__header_subm_name,
}
self.func_list.append(self.header_subm)
self.place_form = {
TOKEN_FORM : self.__place_form,
}
self.func_list.append(self.place_form)
#
# Parse table for <<NOTE_RECORD>> below the level 0 NOTE tag
@ -2500,6 +2543,7 @@ class GedcomParser(UpdateCallback):
TOKEN_RIN : self.__ignore,
TOKEN_CHAN : self.__note_chan,
}
self.func_list.append(self.note_parse_tbl)
# look for existing place titles, build a map
self.place_names = {}
@ -2565,6 +2609,7 @@ class GedcomParser(UpdateCallback):
src.set_handle(handle)
src.set_title(title)
self.dbase.add_source(src, self.trans)
self.__clean_up()
self.__check_xref()
self.dbase.enable_signals()
@ -2575,6 +2620,19 @@ class GedcomParser(UpdateCallback):
message = _("GEDCOM import report: %s errors detected") % \
self.number_of_errors
InfoDialog(message, "".join(self.errors), monospaced=True)
def __clean_up(self):
"""
Break circular references to parsing methods stored in dictionaries
to aid garbage collection
"""
for func_map in self.func_list:
for key in func_map.keys():
del func_map[key]
del func_map
del self.func_list
del self.update
self.lexer.clean_up()
def __find_person_handle(self, gramps_id):
"""