これが私のコードです:
from memory_profiler import profile
@profile
def mess_with_memory():
huge_list = range(20000000)
del huge_list
print "why this kolaveri di?"
これは、インタープリターから実行したときの出力です。
行番号 メモリ使用量の増分 行の内容
3 7.0 MiB 0.0 MiB @profile
4 def mess_with_memory():
5
6 628.5 MiB 621.5 MiB huge_list = range(20000000)
7 476.0 MiB -152.6 MiB del huge_list
8 476.0 MiB 0.0 MiB print "why this kolaveri di"
出力に気付いた場合、巨大なリストを作成すると 621.5 MB が消費され、削除すると 152.6 MB が解放されました。docsを確認したところ、次のステートメントが見つかりました。
the statement del x removes the binding of x from the namespace referenced by the local scope
つまり、オブジェクト自体を削除したのではなく、バインドを解除しただけだと思います。しかし、バインド解除で何をしたので、多くのスペース (152.6 MB) が解放されました。誰かがここで何が起こっているのか説明してくれませんか?