Recently, I've got confused about memory management of python. First is about dict, say I have a composite dict object like
d = {id1: {'x': 'a', 'y': [1,2,3], 'z': {'k', 'v'}}, id2: {...}}
if I call del,
del d[id1]
Will the d[id1]['y'] and d[id1]['z'] be reclaimed together?
Second is about list, I read the answers from here, so I tried it. Here is my code
import sys
import gc
import time
from collections import defaultdict
from pprint import pprint
def f():
d = defaultdict(int)
objects = gc.get_objects()
for o in objects:
d[type(o)] += 1
x = d.items()
x = sorted(x, key=lambda i: i[1], reverse=True)
pprint(x[:5])
def loop():
while True:
leaked = [[x] for x in range(100)]
f()
time.sleep(0.1)
when the range is 100, well, the function f indeed showed me the list was increasing, but when I modify the range to 1000, there is nothing to change, the amount of list keep the same. Anybody could tell me what's the problem?