Issue 9366: Reference leak for local new style class

Issue9366

Created on 2010-07-24 09:46 by kayhayen, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
Referencing.py kayhayen, 2010-07-24 09:46 my reference counting tests
Messages (2)
msg111433 - (view) Author: Kay Hayen (kayhayen) Date: 2010-07-24 09:46
Hello,

I have created tests that check the reference counting and found that the following simple function leaks references in CPython:

def simpleFunction39():
   class Parent( object ):
      pass

I have attached a test that needs to be run with python-dbg and checks the total reference count for many language constructs. Sometimes a warmup can be useful, if CPython caches something, but it doesn't help in this case. Removing object or replacing it with an old style class helps.

I think I saw that 3 references of object leak, and a total of ca. 20 for each call to the function. I suspect a memory leak too.

Use the attached file for reproduction of the problem.
msg112011 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-07-29 21:28
This is caused by the fact that new-style classes create reference cycles.  Try calling the cyclic garbage collector using gc.collect() after the function call, and the leaked references will vanish again.
History
Date User Action Args
2022-04-11 14:57:04adminsetgithub: 53612
2010-07-29 21:28:05georg.brandlsetstatus: open -> closed

nosy: + georg.brandl
messages: + msg112011

superseder: Declaring a class creates circular references
resolution: duplicate

2010-07-24 09:46:39kayhayencreate