[Checkins] SVN: zc.shortcut/trunk/s - add work-around to memory
leak triggered in zope.interface
Benji York
benji at zope.com
Fri Jul 27 16:24:58 EDT 2007
Log message for revision 78389:
- add work-around to memory leak triggered in zope.interface
- bump version number to next release
Changed:
U zc.shortcut/trunk/setup.py
U zc.shortcut/trunk/src/zc/shortcut/proxy.py
-=-
Modified: zc.shortcut/trunk/setup.py
===================================================================
--- zc.shortcut/trunk/setup.py 2007-07-27 20:03:40 UTC (rev 78388)
+++ zc.shortcut/trunk/setup.py 2007-07-27 20:24:58 UTC (rev 78389)
@@ -2,7 +2,7 @@
setup(
name = "zc.shortcut",
- version = "1.0",
+ version = "1.1",
packages = find_packages('src'),
include_package_data = True,
Modified: zc.shortcut/trunk/src/zc/shortcut/proxy.py
===================================================================
--- zc.shortcut/trunk/src/zc/shortcut/proxy.py 2007-07-27 20:03:40 UTC (rev 78388)
+++ zc.shortcut/trunk/src/zc/shortcut/proxy.py 2007-07-27 20:24:58 UTC (rev 78389)
@@ -30,6 +30,13 @@
be the most specific, rather than the least (as in
DecoratorSpecificationDescriptor)."""
+ # As of version 3.4, zope.interface has an unbounded cache of Declaration
+ # objects. This resulted in unbound memory growth when doing lots of
+ # adaptations of zc.shortcut proxies. To avoid the problem until
+ # zope.interface is changed, we essentially memoize the creation of these
+ # objects.
+ declaration_cache = {}
+
def __get__(self, inst, cls=None):
if inst is None:
return declarations.getObjectSpecification(cls)
@@ -38,7 +45,11 @@
# Use type rather than __class__ because inst is a proxy and
# will return the proxied object's class.
dec_impl = interface.implementedBy(type(inst))
- return declarations.Declaration(dec_impl, provided)
+ result = self.declaration_cache.get( (dec_impl, provided) )
+ if result is None:
+ result = declarations.Declaration(dec_impl, provided)
+ self.declaration_cache[dec_impl, provided] = result
+ return result
def __set__(self, inst, v):
raise TypeError("assignment not allowed")
More information about the Checkins
mailing list