[Zope-dev] Memory Leak debug - help

Dieter Maurer dieter@handshake.de
Sat, 25 Aug 2001 02:27:53 +0200 (CEST)


J=FAlio Dinis Silva writes:
 > ....
 > Another thing I done was to track down code which create
 > objects and dont implement nothing to delete them from memory.
 > The tipical error is, for instance, when you in a external method do=20
 > something like:
 >=20
 > ----------------
 >=20
 > file =3D open('BIG','r')
 > buffer =3D file.read(4000000)
 >=20
 > [... execute some code with buffer ...]
 >=20
 > del buffer
 > return something
 >=20
 > ----------------
 >=20
 > Most people forget the "del buffer" part.
This is not necessary in Python.

Python has his own integrated garbage collector (based
on reference counts). It detects cases as above and
automatically cleans up local variables at function
exit. However, cyclic references (direct or indirect)
let this collector fails. The new (Python 2.0 and up)
garbage collector can handle most (but not all) cyclic garbage as well.


Dieter