[Zope-Checkins] CVS: Zope/lib/python/Products/PageTemplates - TALES.py:1.31.6.8
Shane Hathaway
shane@zope.com
Wed, 14 May 2003 17:55:55 -0400
Update of /cvs-repository/Zope/lib/python/Products/PageTemplates
In directory cvs.zope.org:/tmp/cvs-serv5597
Modified Files:
Tag: Zope-2_6-branch
TALES.py
Log Message:
Merge from HEAD.
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.31.6.7 => 1.31.6.8 ===
--- Zope/lib/python/Products/PageTemplates/TALES.py:1.31.6.7 Wed Oct 9 10:37:37 2002
+++ Zope/lib/python/Products/PageTemplates/TALES.py Wed May 14 17:55:54 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