[Python-bugs-list] memory leak in loops (PR#398)
mal@lemburg.com
mal@lemburg.com
Fri, 14 Jul 2000 06:13:50 -0400 (EDT)
Ingo Adler wrote:
>
> > > // The Loop
> > > PyRun_SimpleString(
> > > "y = Y()\n"
> > > "for i in range(1000):\n"
> > > "\tx = y.getX()\n"
> > > "\tx.getNumber()\n"
> >
> > Could be that SWIG doesn't get a chance to cleanup the shadow
> > object for x and y. Try adding
> >
> > del x,y
> >
> > as final script line.
> >
> > Note that SWIG uses Python strings to represent pointers in
> > C++. It uses an internal table to store these.
> >
>
> I changed the code to:
>
> PyRun_SimpleString(
> "y = Y()\n"
> "for i in range(1000):\n"
> "\tx = y.getX()\n"
> "\tx.getNumber()\n"
> "\tdel x\n"
> );
>
> It doesn't change anything.
>
> The memory leak only occurs when I call x.getNumber() in the loop. Otherwise x =
> y.getX() is memory leak free.
Two other possibilities:
1. Python interns the string object used by SWIG to represent
the point. It should then free the memory in the Py_Finalize()
call. If it doesn't, there's a bug to be found ;-)
2. SWIG has the leak. Try using the alternative method of
defining SWIG_COBJECT_TYPES (don't know how this is done --
it seems to be new in SWIG).
--
Marc-Andre Lemburg
______________________________________________________________________
Business: http://www.lemburg.com/
Python Pages: http://www.lemburg.com/python/