During development of a project I've been working on I've been working on I've encountered a problem with garbage collector not able to de-allocate linked lists or even lists.
class B(object):
def __init__(self, previous):
self.previous = previous
def __del__(self):
self.previous = None
self = None
import gc
gc.set_debug(gc.DEBUG_LEAK)
l = []
prev = None
for i in range(1000000):
b = B(prev)
l.append(b)
prev = b
del l[:]
gc.collect()
print gc.garbage
When I check the memory usage before allocation and after allocation and after deletion. Memory usage after allocation is still the same as the Memory usage after deletion. and the garbage collector doesn't complain about any memory leaks.
When I use pympler to track objects in the python environment. the objects don't exist yet there's memory allocated for them.
However, This issue only arises when instances are linked. If an instances don't have a reference to each others. Garbage collector behaves normally.
Any idea why?
del l[:]your full list is still accessible via thebandprevreferences. - sebastian