Sieht aus wie Garbage Collector sammelt nicht die Werte pop
'd aus der dict()
in Python 2.7 (nicht auf Python 3 versucht). Hier ist das Beispiel:dict Pop nicht den Speicher frei
a = dict()
# fill the memory (dict)
for i in xrange(0, 9999999):
a[i] = i
# Memory usage is about 600 MB
# try to free the memory
for i in xrange(0, 9999999):
a.pop(i)
# print the dict and see it is empty
print "%r" % a
# prints: {}
# Memory usage is about 600 MB
import copy
a = copy.copy(a)
# Memory usage decreased to about 200 MB
import gc
gc.collect()
# Memory usage decreased to about 10 MB
Jeder weiß, warum dies passiert und wie dieses Speicherleck Problem zu lösen?
Wie haben Sie die Speichernutzung gemessen? – Daniel
mit 'top' Befehl –
Warum verwenden Sie' pop' anstatt 'del'? –