diff options
author | Benjamin Schubert <ben.c.schubert@gmail.com> | 2019-02-11 15:20:00 +0000 |
---|---|---|
committer | Benjamin Schubert <ben.c.schubert@gmail.com> | 2019-02-13 14:59:47 +0000 |
commit | ec4bbf35a159b5d019d6acd84aa5753b794bb7ee (patch) | |
tree | 131d80259472beae3a03d7ffcaf3fe77906db4f4 | |
parent | 54ec032a9664719c2997c35e5353ca455e917fb9 (diff) | |
download | buildstream-ec4bbf35a159b5d019d6acd84aa5753b794bb7ee.tar.gz |
Cleanup internal Loader cache after loading elements
-rw-r--r-- | buildstream/_loader/loader.py | 19 | ||||
-rw-r--r-- | buildstream/_project.py | 2 | ||||
-rw-r--r-- | buildstream/element.py | 15 |
3 files changed, 36 insertions, 0 deletions
diff --git a/buildstream/_loader/loader.py b/buildstream/_loader/loader.py index d0cfa8522..17d7c63fb 100644 --- a/buildstream/_loader/loader.py +++ b/buildstream/_loader/loader.py @@ -152,8 +152,27 @@ class Loader(): # ret.append(loader._collect_element(element)) + self._clean_caches() + return ret + # clean_caches() + # + # Clean internal loader caches, recursively + # + # When loading the elements, the loaders use caches in order to not load the + # same element twice. These are kept after loading and prevent garbage + # collection. Cleaning them explicitely is required. + # + def _clean_caches(self): + for loader in self._loaders.values(): + # value may be None with nested junctions without overrides + if loader is not None: + loader._clean_caches() + + self._meta_elements = {} + self._elements = {} + ########################################### # Private Methods # ########################################### diff --git a/buildstream/_project.py b/buildstream/_project.py index 028bdcc9f..92ac8cab5 100644 --- a/buildstream/_project.py +++ b/buildstream/_project.py @@ -358,6 +358,8 @@ class Project(): for meta in meta_elements ] + Element._clear_meta_elements_cache() + # Now warn about any redundant source references which may have # been discovered in the resolve() phase. redundant_refs = Element._get_redundant_source_refs() diff --git a/buildstream/element.py b/buildstream/element.py index a3bf59dc6..5ecc25ab2 100644 --- a/buildstream/element.py +++ b/buildstream/element.py @@ -966,6 +966,21 @@ class Element(Plugin): return element + # _clear_meta_elements_cache() + # + # Clear the internal meta elements cache. + # + # When loading elements from meta, we cache already instantiated elements + # in order to not have to load the same elements twice. + # This clears the cache. + # + # It should be called whenever we are done loading all elements in order + # to save memory. + # + @classmethod + def _clear_meta_elements_cache(cls): + cls.__instantiated_elements = {} + # _get_redundant_source_refs() # # Fetches a list of (Source, ref) tuples of all the Sources |