This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Reference leak for local new style class
Type: resource usage Stage:
Components: Interpreter Core Versions: Python 2.6
Status: closed Resolution: duplicate
Dependencies: Superseder: Declaring a class creates circular references
View: 9417
Assigned To: Nosy List: georg.brandl, kayhayen
Priority: normal Keywords:

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

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

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 ):

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