codehaus


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Debugging a memory leak



> On Oct 22, 2020, at 5:51 PM, Pasha Stetsenko <stpasha at gmail.com> wrote:
> 
> Dear Python gurus,
> 
> I'm a maintainer of a python library "datatable" (can be installed from
> PyPi), and i've been recently trying to debug a memory leak that occurs in
> my library.
> The program that exposes the leak is quite simple:
> ```
> import datatable as dt
> import gc  # just in case
> 
> def leak(n=10**7):
>    for i in range(n):
>        z = dt.update()
> 
> leak()
> gc.collect()
> input("Press enter")
> ```

Hi Pasha,
dt.update() is acting on some object(s) outside the leak function body. And so even though, local objects z, i and n are eventually garbage collected, the side-effects of dt.update() are not affected by the return from the leak function. You need to look at your module and carefully trace what happens when dt.update() is executed. It seems to me that any memory consumed when dt.update() is executed will not be released when the leak function returns.

humbly,
Karen