[Zope-Checkins] CVS: Zope/lib/python/Products/PageTemplates - TALES.py:1.38

Shane Hathaway shane@zope.com
Wed, 14 May 2003 17:55:15 -0400


Update of /cvs-repository/Zope/lib/python/Products/PageTemplates
In directory cvs.zope.org:/tmp/cvs-serv4233

Modified Files:
	TALES.py 
Log Message:
Fixed a memory leak in TALES.  If an exception occurs in a repeat block, a
cycle is left behind that includes a SafeMapping, and SafeMappings are not
aware of GC, therefore the cycle can't be collected.  Iterator is also in the
cycle, however, and it does not need a strong reference to the Context object,
since the Context refers to the Iterator.  So Iterators now refer to Context
through a weak reference.


=== Zope/lib/python/Products/PageTemplates/TALES.py 1.37 => 1.38 ===
--- Zope/lib/python/Products/PageTemplates/TALES.py:1.37	Mon Apr  7 13:38:27 2003
+++ Zope/lib/python/Products/PageTemplates/TALES.py	Wed May 14 17:55:14 2003
@@ -18,6 +18,7 @@
 __version__='$Revision$'[11:-2]
 
 import re, sys, ZTUtils
+from weakref import ref
 from MultiMapping import MultiMapping
 from DocumentTemplate.DT_Util import ustr
 from GlobalTranslationService import getGlobalTranslationService
@@ -63,11 +64,13 @@
     def __init__(self, name, seq, context):
         ZTUtils.Iterator.__init__(self, seq)
         self.name = name
-        self._context = context
+        self._context_ref = ref(context)
 
     def next(self):
         if ZTUtils.Iterator.next(self):
-            self._context.setLocal(self.name, self.item)
+            context = self._context_ref()
+            if context is not None:
+                context.setLocal(self.name, self.item)
             return 1
         return 0