Does class definition in constructor of another python class define memory leak?
Not sure if I'm doing something clearly wrong, but the following Python code seems to be leaking in memory:
class A(object):
def __init__(self):
class B(object):
pass
for i in range(0, 100):
a = A()
a = None
From my understanding of Python garbage collection, all objects created should be garbage collected at the end of this sample program. However, there are objects on the heap on the left floating around. The number of objects grows with the number of cycles, but it does so sublinearly.
If I comment out the inner class B
it no longer leaks.
This dummy example has been tested using guppy
both Python 2.7.12. I have not tested it with Python 3, but we observed the same effects as our software, which initially gave an error under Python 2 and 3.
source to share
No one has answered this question yet
Check out similar questions: