]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- InstanceState object now removes circular references to
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 26 Oct 2008 20:02:19 +0000 (20:02 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 26 Oct 2008 20:02:19 +0000 (20:02 +0000)
itself upon disposal to keep it outside of cyclic garbage
collection.

CHANGES
lib/sqlalchemy/orm/attributes.py
lib/sqlalchemy/orm/session.py

diff --git a/CHANGES b/CHANGES
index 19524ca50643d016b0357768f7af5c42b4f7a588..7518c61c2f15267cadb5c6b53c01cdddf7d8d23c 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -38,6 +38,10 @@ CHANGES
       a lazy-load later on.  Backref events still initialize 
       attrbutes and collections for pending instances.
       [ticket:1202]
+    
+    - InstanceState object now removes circular references to 
+      itself upon disposal to keep it outside of cyclic garbage
+      collection.
       
 - sql
     - Further simplified SELECT compilation and its relationship
index 4429d44f41fa22c74ae7fb237374539ee72f1cee..bc8f701e73db0e7119946d63425769a44e9d6bfd 100644 (file)
@@ -794,13 +794,13 @@ class GenericBackrefExtension(interfaces.AttributeExtension):
 class InstanceState(object):
     """tracks state information at the instance level."""
 
-    _cleanup = None
     session_id = None
     key = None
     runid = None
     expired_attributes = EMPTY_SET
     insert_order = None
-
+    dict = None
+    
     def __init__(self, obj, manager):
         self.class_ = obj.__class__
         self.manager = manager
@@ -813,10 +813,22 @@ class InstanceState(object):
         self.pending = {}
         self.expired = False
 
-    def dispose(self):
+    def detach(self):
         if self.session_id:
             del self.session_id
 
+    def dispose(self):
+        if self.session_id:
+            del self.session_id
+        del self.dict
+        del self.obj
+    
+    def _cleanup(self, ref):
+        self.dispose()
+    
+    def obj(self):
+        return None
+            
     @property
     def sort_key(self):
         return self.key and self.key[1] or self.insert_order
@@ -960,6 +972,9 @@ class InstanceState(object):
             if key not in self.committed_state and key not in self.dict)
 
     def expire_attributes(self, attribute_names):
+        if self.dict is None:
+            return
+            
         self.expired_attributes = set(self.expired_attributes)
 
         if attribute_names is None:
index 9eee0e3e13502d0323fb898ad2cf4c9dd9c5c7d0..9292ef3f35dda5cbc520bdf0655cfd7979f63efc 100644 (file)
@@ -787,7 +787,7 @@ class Session(object):
 
         """
         for state in self.identity_map.all_states() + list(self._new):
-            state.dispose()
+            state.detach()
 
         self.identity_map = self._identity_cls()
         self._new = {}
@@ -1012,11 +1012,11 @@ class Session(object):
     def _expunge_state(self, state):
         if state in self._new:
             self._new.pop(state)
-            state.dispose()
+            state.detach()
         elif self.identity_map.contains_state(state):
             self.identity_map.discard(state)
             self._deleted.pop(state, None)
-            state.dispose()
+            state.detach()
 
     def _register_newly_persistent(self, state):
         mapper = _state_mapper(state)