[Zope] Posible memory leak?

Terry Hancock hancock at anansispaceworks.com
Sat Nov 29 01:32:58 EST 2003


On Friday 28 November 2003 10:33 pm, Gabriel Genellina wrote:
> At 27/11/2003 21:17, you wrote:
> >ob = Topic(...)
> >ob.ViewAlias = self.View
> >self._setObject(id, ob)
> >ob = self._getOb(id)
> 
> Is this correct? Or there is a memory leak here?
> In a previous post 
> http://mail.zope.org/pipermail/zope/2002-January/107054.html Max M 
> maxm at mxm.dk said:
> 
> >If your item is subclassing persistent you should expect them to stay in
> >the zodb. And then you should not add them to a list in your own
> >product, but create a subclass of ObjectManager and use the _setObject()
> >method to add the item instances.
> >
> >Else your item class should not subclass persistent.
> >
> >If you want to do it your way by adding item instances to a list in your
> >product you should also be aware that every time your product is
> >changed, or even one of the item instances, the whole object is written
> >to the Data.fs again. Leading to a bloated Data.fs ... if you don't pack
> >it regularly.
> >
> >But doing something like that with that many objects is the wrong way to
> >use the zodb.
> 
>  From this and other sources I've been told *not* to store a Persistent 
> object as an attribute of another object, as this would cause a memory 
> leak. But maybe a PersistentMapping is specially crafted? I dont see 
> anything special in its source.

Hmm. Well, this is a little different -- storing an attribute is not the same
as including the object in a list:

Persistent object --(attribute)--> Persistent Object

vs

Persistent object --(attribute)--> Mutable List --(item)--> Persistent Object

and Mutable + Non-Persistent objects are NOT supposed to be used
in Persistent Objects (but you can use the _p_changed flag to do it?).

The proposed solution (an Object Manager):

Persistent object --(attribute)--> Persistent ObjectMgr --(attribute)--> Persistent Object

suggests that the 1st case is okay.  (But doesn't prove it).  It's possible
that I should be using "_setObject" instead of "=" to create the ViewAlias
attribute. (?) Seeing as I don't really understand what the difference is.

> Perhaps the enlightened people could explain the rules to avoid memory leaks...

Perhaps.  I hadn't heard of this problem.  I'll look out for the memory leak
in case it is an issue in my case.

Thanks,
Terry

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com



More information about the Zope mailing list