classification
Title: Reference leak for local new style class
Type: resource usage Stage:
Components: Interpreter Core Versions: Python 2.6
process
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 2010-07-29 21:28 by georg.brandl. 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
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