From: Zac Medico Date: Sun, 17 Aug 2008 23:05:32 +0000 (-0000) Subject: Bug #229069 - Before deleting the depgraph, break references pointing X-Git-Tag: v2.1.4.5~5 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=b7860791b962b9ca8c2cb113c9fe7cdbc18933b9;p=portage.git Bug #229069 - Before deleting the depgraph, break references pointing to the depgraph from Package instances in the merge list. This helps reduce the heap size a lot. (trunk r10775) svn path=/main/branches/2.1.2/; revision=11431 --- diff --git a/bin/emerge b/bin/emerge index 9f1d51156..040fb7184 100755 --- a/bin/emerge +++ b/bin/emerge @@ -1908,6 +1908,15 @@ class PackageVirtualDbapi(portage.dbapi): self._cp_map = {} self._cpv_map = {} + def clear(self): + """ + Remove all packages. + """ + if self._cpv_map: + self._clear_cache() + self._cp_map.clear() + self._cpv_map.clear() + def copy(self): obj = PackageVirtualDbapi(self.settings) obj._match_cache = self._match_cache.copy() @@ -3906,6 +3915,29 @@ class depgraph(object): retlist.reverse() return retlist + def break_refs(self, mergelist): + """ + Take a mergelist like that returned from self.altlist() and + break any references that lead back to the depgraph. This is + useful if you want to hold references to packages without + also holding the depgraph on the heap. + """ + for node in mergelist: + if not isinstance(node, Package): + continue + + # The visible packages cache has fullfilled it's purpose + # and it's no longer needed, so free the memory. + node.root_config.visible_pkgs.clear() + + if isinstance(node.root_config.trees["vartree"], FakeVartree): + # The FakeVartree references the _package_cache which + # references the depgraph. So that Package instances don't + # hold the depgraph and FakeVartree on the heap, replace + # the FakeVartree reference with the real vartree. + node.root_config.trees["vartree"] = \ + self._trees_orig[node.root]["vartree"] + def _resolve_conflicts(self): if not self._complete_graph(): raise self._unknown_internal_error() @@ -8665,6 +8697,7 @@ def action_build(settings, trees, mtimedb, mtimedb.filename = None time.sleep(3) # allow the parent to have first fetch mymergelist = mydepgraph.altlist() + mydepgraph.break_refs(mymergelist) del mydepgraph clear_caches(trees) @@ -8708,6 +8741,7 @@ def action_build(settings, trees, mtimedb, pkglist = mydepgraph.altlist() mydepgraph.saveNomergeFavorites() + mydepgraph.break_refs(pkglist) del mydepgraph clear_caches(trees)