From f785c9e3aa9aef96afcfdc15ef78333f3769dd93 Mon Sep 17 00:00:00 2001 From: Julien Muchembled <jm@nexedi.com> Date: Wed, 25 Aug 2010 16:34:59 +0000 Subject: [PATCH] Fix severe memory leak (and speed loss) git-svn-id: https://svn.erp5.org/repos/public/erp5/sandbox/amount_generator@38014 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5/mixin/composition.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/product/ERP5/mixin/composition.py b/product/ERP5/mixin/composition.py index fce74a216c..37b8f25055 100644 --- a/product/ERP5/mixin/composition.py +++ b/product/ERP5/mixin/composition.py @@ -113,11 +113,18 @@ class asComposedDocument(object): This class should be seen as a function, and it is named accordingly. It is out of CompositionMixin class to avoid excessive indentation. """ + # Cache created classes to make other caches (like Base.aq_portal_type) + # useful and avoid memory leaks. + __class_cache = {} def __new__(cls, orig_self, portal_type_list=None): self = orig_self.asContext(_portal_type_list=portal_type_list) # XXX-JPS orig_self -> original_self - please follow conventions base_class = self.__class__ - self.__class__ = type(base_class.__name__, (cls, base_class, BusinessProcess), {}) + try: + self.__class__ = cls.__class_cache[base_class] + except KeyError: + cls.__class_cache[base_class] = self.__class__ = \ + type(base_class.__name__, (cls, base_class, BusinessProcess), {}) # here we could inherit many "useful" classes dynamically - h茅h茅 # that would be a "real" abstract composition system self._effective_model_list, specialise_value_list = \ -- 2.30.9