[Zope] memory leak in a very simple product. Way?
Christoph Wierling
wierling@molgen.mpg.de
Wed, 16 Jan 2002 11:19:53 +0100 (MET)
[Thomas B. Passin]
>
> [Christoph Wierling]
> >
> > 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?
> >
> >
> > here is the code:
> >
> > ...
>
> > 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
> >
>
> I think you really want to do this:
>
> tree = []
> for i in xrange(200):
> n = item(str(i),i)
> tree.append(n)
> self._tree = tree
>
Thanks for the suggestion. Your code does about the same as my did -
it also reproduces the 20000 references to objects of the item-class.
And I also don't get rid of the 20000 references. I tried it! :-(
christoph