GC question

Martin von Loewis loewis at informatik.hu-berlin.de
Fri Nov 9 14:05:49 CET 2001

Kerim Borchaev <warkid at storm.ru> writes:

> I'm trying to control memory leakage in my code.
> I need to know which objects wasn't deallocated in proper moment.

Then using DEBUG_LEAK is the right approach. I still don't know what
"problem" you've encountered. When you write

def fun():
    class C:
        def m(self):
            g = C()

you *will* create an unreferenced cycle. You should know that the
implementation of nested scopes creates "cell" objects, which are
holders for variables in nested scopes. Since "C" is a name used in a
nested scope, a cell object is introduced for C. That gives you the

cellobject -> class C -> C.__dict__ -> C.m -> C.m.co_freevars -> cellobject


More information about the Python-list mailing list