diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-07-10 20:01:56 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-07-10 20:01:56 +0000 |
commit | 910961fccdf9fe6933c56c595c1126df132a31ff (patch) | |
tree | 90dc2f1516811490216fab6b3e5d5b26c3ceeb81 /lib/sqlalchemy/orm/state.py | |
parent | 4e4102f64d0b467649cb372460945a6a7f910884 (diff) | |
download | sqlalchemy-910961fccdf9fe6933c56c595c1126df132a31ff.tar.gz |
- 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.
Diffstat (limited to 'lib/sqlalchemy/orm/state.py')
-rw-r--r-- | lib/sqlalchemy/orm/state.py | 9 |
1 files changed, 7 insertions, 2 deletions
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. |