[Zope] memory leak in a very simple product. Way?

Christoph Wierling wierling@molgen.mpg.de
Tue, 15 Jan 2002 20:03:29 +0100 (MET)


Hi,

I've writte a very simple product which creates 100 simple objects
(testProd class instances) and each of these objects has a list-attribute
which contains 200 other objects (item class instances). (Please find the
code at the end of this mail.)
By starting the addTestProd-function I create 20000 references to
item objects, as the Zope-debug option as well as the leakFinder-product
tell me.
But I'll never get rid of these references and earlier or later I'll run
out of memory.

Could anybody explain me, way this simple product is leaking like a sieve?
And how I can get rid of the references?

thanks for your help in advance,
Christoph


here is the code:

__init__.py:

import testProd2

def initialize(context):
    """ initialize this product """
    context.registerClass(
        testProd2.testProd,
	permission = 'Add testProd',
        constructors=(testProd2.addTestProd,))


testProd2.py:

import OFS.SimpleItem as SimpleItem
from OFS.SimpleItem import Item

def addTestProd(self):
    """ add TestProd """
    for c in range(100):
        name = 'test' + str(c)
        self._setObject(name, testProd(name))

class testProd(SimpleItem.SimpleItem):
    """ testProd docu """

    meta_type = 'testProd'

    def __init__(self, id, title = ''):
        self.id = id
        self.title = title

        self._tree = []

        for i in xrange(200):
            n = item(str(i),i)
            tree = self._tree
            tree.append(n)
            self._tree = tree

class item(Item):
    """ item """

    def __init__(self, id, value):
        self.id = id
        self.value = value