Consider the following script:
import numpy as np
import tracemalloc
def zero_mem():
a = np.zeros((100, 100))
def nonzero_mem():
b = np.random.randn(100, 100)
if __name__ == "__main__":
tracemalloc.start()
zero_mem()
print(tracemalloc.get_traced_memory())
tracemalloc.stop()
tracemalloc.start()
nonzero_mem()
print(tracemalloc.get_traced_memory())
tracemalloc.stop()
The output running numpy 1.22.2
on python 3.8.10
is
(0, 80096)
(72, 80168)
The question is: why isn't the second row (0, 80168)
? In other words: why is there memory still in use after nonzero_mem()
, unlike when calling zero_mem()
?
Aucun commentaire:
Enregistrer un commentaire