diff options
| author | Raphael Collet <rco@openerp.com> | 2017-03-15 16:47:56 +0100 |
|---|---|---|
| committer | Raphael Collet <rco@openerp.com> | 2017-03-21 15:50:20 +0100 |
| commit | c9edb9dccbf09d0bd5fe17273f4f394b1f79c01c (patch) | |
| tree | 313e167dea388a4fe096c3040fd3abf4c71b6d41 /odoo/modules | |
| parent | 3b774ee32948237d102443c0fcf291bfa5c80a7f (diff) | |
[FIX] registry: use a weak dictionary for `model_cache` to avoid memory leaks
The class attribute `model_cache` refers to model classes, which refer to their
own registry. This cache potentially keeps all past registries alive!
Diffstat (limited to 'odoo/modules')
| -rw-r--r-- | odoo/modules/registry.py | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/odoo/modules/registry.py b/odoo/modules/registry.py index 6e5378d33c8..1926ad33776 100644 --- a/odoo/modules/registry.py +++ b/odoo/modules/registry.py @@ -7,6 +7,7 @@ from collections import Mapping, defaultdict, deque from contextlib import closing from operator import attrgetter +from weakref import WeakValueDictionary import logging import os import threading @@ -30,6 +31,9 @@ class Registry(Mapping): _lock = threading.RLock() _saved_lock = None + # a cache for model classes, indexed by their base classes + model_cache = WeakValueDictionary() + @lazy_classproperty def registries(cls): """ A mapping from database names to registries. """ @@ -177,12 +181,6 @@ class Registry(Mapping): """ Add or replace a model in the registry.""" self.models[model_name] = model - @lazy_classproperty - def model_cache(cls): - """ A cache for model classes, indexed by their base classes. """ - # we cache 256 classes per registry on average - return LRU(cls.registries.count * 256) - @lazy_property def field_sequence(self): """ Return a function mapping a field to an integer. The value of a |
