From: Mike Bayer Date: Sat, 14 Jul 2012 18:24:51 +0000 (-0400) Subject: - [feature] The registry of classes X-Git-Tag: rel_0_8_0b1~330 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6dad6332cd0b777e4d876f51fada4fdf31299c53;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - [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] --- diff --git a/CHANGES b/CHANGES index 72787307fd..e94c55601e 100644 --- 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 diff --git a/lib/sqlalchemy/ext/declarative.py b/lib/sqlalchemy/ext/declarative.py index 23346730fd..651a94970f 100755 --- a/lib/sqlalchemy/ext/declarative.py +++ b/lib/sqlalchemy/ext/declarative.py @@ -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,