Perform line-by-line memory analysis
masterTo analyze memory consumption line-by-line, decorate the target function with @profile. You can then run your script using the memory_profiler module via the Python interpreter. This will output a table showing line numbers, memory usage, increments, occurrences, and the code content.
@profile
def my_func():
a = [1] * (10 ** 6)
b = [2] * (2 * 10 ** 7)
del b
return a
if __name__ == '__main__':
my_func()Run the analysis
$ python -m memory_profiler example.py