ガベージコレクタのように、pop
がdict()
のpython 2.7(python 3では試していません)の値を収集していないようです。ここに例があります:dict popはメモリを解放していません
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
誰もがこのようなことが起こり、このメモリリークの問題を解決する方法を知っていますか?
どのようにメモリ使用量を測定しましたか? – Daniel
'top'コマンドを使用 –
なぜ' del'ではなく 'pop'を使うのですか? –