-
Notifications
You must be signed in to change notification settings - Fork 37
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
Program and Kernel are leaking memory #24
Comments
From that exellent overview I think https://github.com/jakebolewski/OpenCL.jl/blob/master/src/kernel.jl#L44 needs to be set to false. I'm not around to test, does this fix the leak? |
@jakebolewski That is the change I introduced in 721c962 similar to what I did yesterday for context. |
...which I obviously didn't read carefully enough ;-) I'm almost out of suggestions, I'll have to think on this one a bit. Does forcing a Base.gc() every iteration change the behavior you are seeing? |
Yes it does. Calling the gc() causes the memory leak to disappear. function leaky()
....
p = cl.Program(ctx, source=simpleKernel) |> cl.build!
k = cl.Kernel(p, "add")
gc()
return nothing
end |
Ok, what about forcing a gc() every Nth iteration? Are all objects gc'd? What about forcing a gc() just before the end? If the leak goes away this has something to do with the libraries interaction with Julia's garbage collector and I'll have to punt on that. |
The smaller the step size I call the gc in the less memory leak occurs...
So #22 fixed the problems I had in my application where I first encountered the memory leaks. The issue here is not that likely to appear in the wild since you gotta do pretty weird stuff that warrant creating programs and kernels in a tight loop. |
closed in favor of #46 |
This issue is slightly different from #21 and to minimize the confusion I decided to open up a second issue.
The following code leaks memory:
Note: The Buffer creation is only there to make it abundantly clear when you look at the memory output.
Substituting leaky with one of the following fixes the memory leak
or
Adding a Kernel into the mix creates the leak again:
and manually releasing the Kernel fixes the memory leak
My intuition is that in this case we don't have the problem of #21 where we retain too often, but something different going on.
Please note that the last example will leak memory without the changes in 721c962 .
Since the memory leak only appears for me when the program is build I thought that maybe clProgramBuild increase the ref count by one, but issuing a second clReleaseProgram when the program is build resulted in a segmentation fault and since the manual release works it might have something to do with the order you release program.
The text was updated successfully, but these errors were encountered: