From 910961fccdf9fe6933c56c595c1126df132a31ff Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 10 Jul 2009 20:01:56 +0000 Subject: - Fixed potential memory leak whereby previously pickled objects placed back in a session would not be fully garbage collected unless the Session were explicitly closed out. --- lib/sqlalchemy/orm/state.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/sqlalchemy/orm/state.py b/lib/sqlalchemy/orm/state.py index 1b7b3fbd5..10a0f43ee 100644 --- a/lib/sqlalchemy/orm/state.py +++ b/lib/sqlalchemy/orm/state.py @@ -16,6 +16,7 @@ class InstanceState(object): load_path = () insert_order = None mutable_dict = None + _strong_obj = None def __init__(self, obj, manager): self.class_ = obj.__class__ @@ -139,7 +140,7 @@ class InstanceState(object): return d def __setstate__(self, state): - self.obj = weakref.ref(state['instance']) + self.obj = weakref.ref(state['instance'], self._cleanup) self.class_ = state['instance'].__class__ self.manager = manager_of_class(self.class_) @@ -150,6 +151,9 @@ class InstanceState(object): self.expired = state.get('expired', False) self.callables = state.get('callables', {}) + if self.modified: + self._strong_obj = state['instance'] + self.__dict__.update( (k, state[k]) for k in ( 'key', 'load_options', 'expired_attributes', 'mutable_dict' @@ -272,7 +276,8 @@ class InstanceState(object): instance_dict._modified.add(self) self.modified = True - self._strong_obj = self.obj() + if not self._strong_obj: + self._strong_obj = self.obj() def commit(self, dict_, keys): """Commit attributes. -- cgit v1.2.1