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

Max M maxm@mxm.dk
Wed, 16 Jan 2002 11:42:30 +0100


Christoph Wierling wrote:

 > [Thomas B. Passin]


 >>>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


The only thing I can guess at is that xrange plays funnily with Zope in 
this case. For some reason the list items generated by xrange() might 
not be released for garbage colletcion.

If so it is probably a bug.

Try:

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 range(200):
             n = item(str(i),i)
             self._tree.append(n)


On another note. Why do you do all the :

tree = self._tree
tree.append(n)
self._tree = tree

isn't:

self._tree.append(n)

Just as good, and 2 lines shorter?

regards Max M