Domanda

I read several ZODB tutorials but here is one thing I still don't get: How do you free memory that is already serialized (and committed) to the (say) FileStorage?

More specifically, I want the following code to stop eating all my memory:

for i in xrange(bignumber):
    iobtree[i]=Bigobject() # Bigobject is about 1Mb
    if(i%10==0): 
        transaction.commit() # or savepoint(True)
transaction.commit()

How can this be achieved? Is it possible to release references stored by iobtree and replace them by 'weak references' that would be accessible on demand?

È stato utile?

Soluzione

Creating savepoints and commiting the transaction already clears a lot of you memory.

  • You'll need to check what your ZODB cache parameters are set to, and tune these as necessary. The cache size parameter indicates the number of objects cached, not bytes, so you'll have to adjust this based on the size of your objects.

  • You can try and call .cacheMinimize() on the ZODB connection object, this explicitly deactivates any unmodified (or already committed) objects in the cache.

Other than that, do note that even when Python frees objects from memory, the OS doesn't always reclaim that freed memory until it is needed for something else. OS-reported memory usage doesn't necessarily reflect actual memory requirements for a Python process.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top