[Zope] Posible memory leak?
Dieter Maurer
dieter at handshake.de
Sun Nov 30 17:58:37 EST 2003
Gabriel Genellina wrote at 2003-11-29 01:33 -0300:
> At 27/11/2003 21:17, you wrote:
> >I added a step in my manage_addTopic() script like
> >this to make a local reference to the "View" attrib I'm
> >trying to acquire:
> >
> >ob = Topic(...)
> >ob.ViewAlias = self.View
> >self._setObject(id, ob)
> >ob = self._getOb(id)
> >
> >View is a PersistentMapping, so I presume it will act like
> >a normal mutable Python object (so when I make changes
> >to its contents, they'll show up in the alias). I'll have
> >to test this, anyway, to make sure, of course.
> >
> >In the __setstate__ method, Topic computes using the
> >ViewAlias which is a local attribute:
> >
> >for view in self.ViewAlias.keys():
> > #... do some stuff with this view info
> > pass
>
> Is this correct?
This looks okay.
> Or there is a memory leak here?
I do not see one (which does not necessarily mean there are none).
> 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.
I do this routinely. There is only one problem: when you change
the list, you must tell the object that you did this.
The problem disappears when you use a persistent object, such
as a "PersistentList".
Your code does not use the problematic case.
> From this and other sources I've been told *not* to store a Persistent
> object as an attribute of another object,
Precisely, this does "ObjectManager": it stores its content items
(persistent objects) as attributes of itself.
As you see by this prominent example: there is not problem to do this.
--
Dieter
More information about the Zope
mailing list