]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- [feature] The registry of classes
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 14 Jul 2012 18:24:51 +0000 (14:24 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 14 Jul 2012 18:24:51 +0000 (14:24 -0400)
    in declarative_base() is now a
    WeakValueDictionary.  So subclasses of
    "Base" that are dereferenced will be
    garbage collected, *if they are not
    referred to by any other mappers/superclass
    mappers*.  [ticket:2526]

CHANGES
lib/sqlalchemy/ext/declarative.py

diff --git a/CHANGES b/CHANGES
index 72787307fdd682ebaec742dfdf97b650596d7e67..e94c55601e86a8572eeeaf11f8dd0c559254a560 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -151,6 +151,14 @@ underneath "0.7.xx".
     need autoflush w pre-attached object.
     [ticket:2464]
 
+  - [feature] The registry of classes
+    in declarative_base() is now a
+    WeakValueDictionary.  So subclasses of
+    "Base" that are dereferenced will be
+    garbage collected, *if they are not
+    referred to by any other mappers/superclass
+    mappers*.  [ticket:2526]
+
   - [removed] Deprecated identifiers removed:
 
     * allow_null_pks mapper() argument
index 23346730fd052903a512ae17bd25d137117287e3..651a94970fcd3005817e33ce07c6e7a0fd4965c6 100755 (executable)
@@ -1036,7 +1036,7 @@ from sqlalchemy import util, exc
 from sqlalchemy.sql import util as sql_util, expression
 from sqlalchemy import event
 from sqlalchemy.orm.util import polymorphic_union, _mapper_or_none
-
+import weakref
 
 __all__ = 'declarative_base', 'synonym_for', \
             'comparable_using', 'instrument_declarative'
@@ -1718,7 +1718,7 @@ def declarative_base(bind=None, metadata=None, mapper=None, cls=object,
         lcl_metadata.bind = bind
 
     if class_registry is None:
-        class_registry = {}
+        class_registry = weakref.WeakValueDictionary()
 
     bases = not isinstance(cls, tuple) and (cls,) or cls
     class_dict = dict(_decl_class_registry=class_registry,