[Zope-dev] RE: Memory Leak Question
Jim Fulton
jim at zope.com
Tue Nov 22 17:09:36 EST 2005
Dan Pozmanter wrote:
> Sure thing:
>
> I was mucking around in _Acquisition.c with getattr, findattr, etc,
> and I noticed checked to see if my code was leaky.
> It was! I then checked just vanilla code, and found the same
> leak (only much much smaller).
>
> So here is what I did to make things more visible:
> In Wrapper_getattro, I simply added a while loop,
> and another call to Wrapper_findattr before the return statement "
> return Wrapper_findattr(self, oname, NULL, NULL, NULL, 1, 1, 0, 0);".
> Loop it 1000 times for some fireworks, 5 times for a more modest
> display.
>
> Looping other calls (such as Wrapper_acquire before " return
> Wrapper_acquire(self, oname, filter, extra, orig, explicit,
> containment);" in Wrapper_findattr)
> does not produce a similar leak.
>
> So. To reproduce:
>
> Edit _Acquisition.c
> Function Wrapper_getattro
> add
> " int i = 0;"
> at the top.
> then, if self->obj ... and all that, add:
> "
> while (i < xyz) {
> Wrapper_findattr(self, oname, NULL, NULL, NULL, 1, 1, 0, 0);
> i++;
> }
> "
Wrapper_findattr (like, for example, PyObject_GetAttr) returns a
*new* reference to the result of the attribute access. So this would,
of course, cause a leak. If you have code that is calling Wrapper_findattr
and not taking care of the new reference, then it is not surprizing that
you have a leak.
Jim
--
Jim Fulton mailto:jim at zope.com Python Powered!
CTO (540) 361-1714 http://www.python.org
Zope Corporation http://www.zope.com http://www.zope.org
More information about the Zope-Dev
mailing list