memory_leak module

memory_leak provides useful methods for finding memory leaks in your Python code.

memory_leak makes to output the Python standard library tracemalloc in an easy-to-read format. It also comes with a summary using the popular library Pympler.

It will be useful in the early stages when you have no idea where the memory leak is. After that, attach the @profile() decorator to the methods likely to cause memory leaks using memory_profiler module, you can search the point at memory leak.

param limit

(int) Limit output lines.

param key_type

(str) Select ‘lineno’ or ‘traceback’ output. Defaults to ‘lineno’.

param nframe

(int, optional) This can be specified only when key_type is ‘traceback’. Defaults to 5.

Example

>>> from memory_leak import Memory_leak
>>> m = Memory_leak(limit = 2, key_type = 'lineno')
>>> m.memory_leak_analyze_start()
>>>
>>> # ...Your application code
>>>
>>> m.memory_leak_analyze_stop()
Reference:
Document:

https://ykesamaru.github.io/Memory_leak/

GitHub:

https://github.com/yKesamaru/Memory_leak

Zenn:

https://zenn.dev/ykesamaru/articles/bd403aa6d03100

Special thanks to @nariaki3551(Nariaki Tateiwa) who created setup.py.

class memory_leak.Memory_leak(limit: int, key_type: str, **kwargs: int)[source]

Bases: object

Output the result of the tracemalloc and Pympler module with formatted.

memory_leak_analyze_start() None[source]

Specify start point.

memory_leak_analyze_stop() None[source]

Specify end point.