GC question

Martin von Loewis loewis at informatik.hu-berlin.de
Fri Nov 9 08:05:49 EST 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()
fun()


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
cycle

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

HTH,
Martin



More information about the Python-list mailing list