Description
Describe the issue:
At my job, I was doing some memory analysis on our application in order to identify possible memory leaks.
To do this, I've used the package memray
, which offers a lot of handy commands to identify memory leaks by generating a flame graphs that identifies memory chuncks allocated after tracking starts and not deallocated after tracking ends.
Reproduce the code example:
# test_numpy_leak.py
import numpy as np
def main():
for _ in range(1_000_000):
a = np.array([[1, 2], [3, 5]])
b = np.array([1, 2])
np.linalg.solve(a, b)
if __name__ == "__main__":
main()
Error message:
In order to reproduce the analysis, use the following commands:
PYTHONMALLOC=malloc python -m memray run --native test_numpy_leak.py
python -m memray flamegraph --leaks memray-test_numpy_leak.py.XXXX.bin
, whereXXXX
is the number of the file specified in its name.
After running these commands, it generates an HTML file, so you can open in your browser and see a flame graph, like the one above. I highlighted in red the section where memray
reports a memory leak, if I hover it, it says that 4 allocations was made (32.0 MiB in total).
The line of code that is leaking memory is the following:
Line 410 in 41c6bbe
Python and NumPy Versions:
1.26.2
3.11.9 (main, Jul 19 2024, 18:26:46) [GCC 14.1.1 20240522]
Runtime Environment:
No response
Context for the issue:
Actually, I was just worried if this memory leak could scale and do more damage