[ZODB-Dev] Old memory leak related to the ObjectWriter?

Jeremy Hylton jeremy at alum.mit.edu
Thu Sep 1 10:56:59 EDT 2005


What version of Python?  I believe we added cyclic GC support to
picklers to address this problem, but that was probably for Python
2.4.

Jeremy

On 9/1/05, Pierre Dumonceau <pierre.dumonceau at cetic.be> wrote:
> Hi,
> 
> I am involved in the maintenance of an application using ZODB and
> Zope-2.8.0-final. After some investigation I noticed what could be an
> old memory leak related to the ObjectWriter (cycle with the pickler) in
> ZODB, as can be seen running this short program:
> 
> import os, os.path
> from ZODB import FileStorage, DB
> import transaction
> import sys
> import gc
> 
> class ZODBStore:
>    def __init__(self, name):
>        self.name = name
>        self.absPathName = os.path.dirname(os.path.abspath(name))
>    def Connect(self):
>        self.file = FileStorage.FileStorage(self.name)
>        self.db = DB(self.file)
>        self.connection = self.db.open()
>        self.root = self.connection.root()
>        self.transaction = transaction.begin()
>    def Disconnect(self):
>        self.Commit()
>        self.connection.close()
>        self.db.close()
>        self.file.close()
>    def Commit(self):
>        self.transaction.commit()
>    def Abort(self):
>        self.transaction.abort()
> 
> if __name__ == "__main__":
>    ObjectStore = ZODBStore("test.fs")
>    ObjectStore.Connect()
>    ObjectStore.root['Employees'] = ['Jack', 'Joe', 'Bob']
>    ObjectStore.Disconnect()
> 
>    gc.enable()
>    gc.set_debug(gc.DEBUG_LEAK)
>    resultFile = open('resultConnectionLeak.txt', 'a+')
>    gc.collect()
>    for x in gc.garbage:
>        msg = '>>>> Garbage ' + str(type(x)) + ' ' + str(x) + '\n     '
>        msg += x.__class__.__name__ + ' at ' + str(hex(id(x))) + '\n'
>        resultFile.write(msg)
>    resultFile.close()
> 
> I fixed it by adding a close function to the ObjectWriter in
> serialize.py and calling it explicitly from connection.py (modification
> found in the CVS).
> def close(self):
>    self._p.persistent_id = None
>    self._p = None
> _______________________________________________
> For more information about ZODB, see the ZODB Wiki:
> http://www.zope.org/Wikis/ZODB/
> 
> ZODB-Dev mailing list  -  ZODB-Dev at zope.org
> http://mail.zope.org/mailman/listinfo/zodb-dev
>


More information about the ZODB-Dev mailing list