Build-in libraries
import tracemalloc
print(tracemalloc.start())
# ...
# my ugly code
# ...
print(tracemalloc.get_traced_memory())
# shows (current_usage, peak)
Tools
- pythonprofilers/memory_profiler: Monitor Memory usage of Python code
- bloomberg/memray: Memray is a memory profiler for Python
# need pip install memory_profiler
from memory_profiler import profile
@profile
def my_ugly_func():
# ...
# ...
# show memory usage line by line
Other
Tkinter initial use 41.9 MB
Top comments (0)