GC question

Kerim Borchaev warkid at storm.ru
Fri Nov 9 11:52:02 EST 2001


Hello Martin,

Friday, November 09, 2001, 4:05:49 PM, you wrote:

MvL> 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.

MvL> Then using DEBUG_LEAK is the right approach. I still don't know what
MvL> "problem" you've encountered.
The essence of the problem you explained below I suppose? ;-)

MvL> When you write

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


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

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

Now I get it. But (may be only for me) the code above
didn't look obviously "wrong". Although it's pretty simple.
But, again, may be it's only for me...

Best regards,
 Kerim                            mailto:warkid at storm.ru






More information about the Python-list mailing list