Here is a python program I'm running with numpy. Why does it seems to use so much memory even after I delete the np.array? Is this normal? Or Is there something I'm not understanding about memory and how it is allocated?
Python 3.7.9 (default, Aug 31 2020, 12:42:55)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os, psutil
>>> def memory():
... pid = os.getpid()
... proc = psutil.Process(pid)
... mem = proc.memory_info()
... print('Memory used: {:.2f} MB'.format(mem.vms/1024/1024))
...
>>> import numpy as np
>>> memory()
Memory used: 269.27 MB
>>> a = np.random.rand(100,100)
>>> memory()
Memory used: 269.27 MB
>>> b = a @ a
>>> memory()
Memory used: 2932.79 MB
>>> del b
>>> memory()
Memory used: 2932.79 MB