-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
numba.jit memory leak #1361
Comments
I'm using Numba v0.20.0 by the way. |
Do you have a real-world workload where this is affecting you? We try to release resources when we can, but I wouldn't be surprised if we don't release all memory (especially because LLVM itself may prevent us from that). |
Thanks for replying! I have a dll that embeds Python into a system that is up for days. A memory leak, though small, could mean I'd have to reset the system every few days. |
Well, if you compile a function in a loop, you will lose a lot of time compiling, so it's much better to move the |
That's right. In my case there is a Python function being called, say, every few minutes by the enclosing system (which is not aware of the Python details). This function in turn uses @jit. So it's not as bad as a very rapid loop doing jits. I could solve this by keeping a state between function calls as you suggest. I guess I wouldn't prioritize this issue very high, but it would be nice to know there are no leaks to require such workarounds :) |
I've tried this again. Here is a script that shows a bit more useful info during running (and also calls gc.collect() from time to time): https://gist.github.com/pitrou/bada94f31e1c8891585c |
I found a similar memory leak issue when putting a jitted function inside another function and calling that from a loop. There is no leak when the jitted function is pulled out of the outer function. See file for leak and workaround: https://gist.github.com/ajkur/b5e1f7908d1d2a1f2c43b82690cc82e9 |
I've stumbled into this when jitting closures using numba 0.40 |
Thank you @ajkur. I had a scenario like this: @njit
def fun1():
for a in fun2():
# do something
return
@njit
def fun2():
for i in range(100):
yield i After removing the second function by placing its contents directly into the first, the memory over time went from this: to this: |
I'm also having an issue with memory leaks with It seems that
|
@trianta2 thanks for reporting this, I have tried this locally and can confirm I am able to reproduce your findings. |
Just a simple example to reproduce import gc
import numpy as np
import numba
@numba.jit(cache=False)
def main(x):
x**2
gc.enable( )
gc.set_debug(gc.DEBUG_SAVEALL)
x = np.random.random((10,))
main(x)
gc.collect()
assert not len(gc.garbage), f"found {len(gc.garbage)} objects." raises AssertionError |
@Enolerobotti thank you for submitting this. I removed all Numba references from your example and I also receive an
|
The following loop produces a memory leak. If nb.jit is taken out of the loop, there is no leak.
The text was updated successfully, but these errors were encountered: