[Zope-dev] Using ZODB standalone

A.M. Kuchling akuchlin@mems-exchange.org
Sat, 11 Sep 1999 14:10:19 -0400


I'm experimenting with using ZODB3 to store a tree of objects, but
don't understand what I'm doing.  My expectation is that the amount of
memory used should be bounded, because objects should be flushed from
the cache when they haven't been accessed in a while.  Instead, the
Python process grows continually.  Here's the simple test code I'm
playing with:

# Open a ZODB; this all seems fine.
from ZODB import FileStorage, DB
fs = FileStorage.FileStorage('/scratch/mydata.fs')
db = DB( fs )
conn = db.open()

# Here's my test class -- do I need to do more?
import Persistence
class myClass(Persistence.Persistent):
    pass

# Create a single root object
c = myClass()
root = conn.root()
root['c'] = c

# Loop for a long time, creating new myClass instances and adding them
# as an attribute to the last instance.  (Perhaps ZODB needs to keep
# the whole path from the root object in memory, and this test should
# be building a bushy tree instead of a constantly deepening chain?)

for i in xrange(100000):
    c.num = i
    c.subobject = myClass()
    c = c.subobject
    # Do commits every few objects.
    if (i % 100) == 0:
        print 'Committing'
        get_transaction().commit()

Do I need to call some method to force a GC of the cache?  What am I
missing?

Incidentally, are Jim's slides from the DCPIGgies meeting available
online?  I suspect their discussion of ZODB3 (and the slides showing
the steps in using it) would be helpful.

-- 
A.M. Kuchling			http://starship.python.net/crew/amk/
prompt. n. (Unix) A symbol on the screen indicating which shell is attacking
you.
    -- Stan Kelly-Bootle, _The Computer Contradictionary_