考慮這兩個代碼,我在Python控制檯運行:Python3.4內存使用
l=[]
for i in range(0,1000): l.append("."*1000000)
# if you check your taskmanager now, python is using nearly 900MB
del l
# now python3 immediately free-d the memory
現在考慮這個:
l=[]
for i in range(0,1000): l.append("."*1000000)
l.append(l)
# if you check your taskmanager now, python is using nearly 900MB
del l
# now python3 won't free the memory
因爲我與這些類型的對象的工作,和我需要將它們從我的內存中釋放出來,我需要知道爲了讓python認識到它需要刪除相應的內存。
PS:我正在使用Windows7。