import OpenCL; const cl = OpenCLfunction leaky() device, ctx, queue = cl.create_compute_context() # Allocate buffer a = cl.Buffer(Float64, ctx, :rw, 1024*1024) cl.flush(queue) cl.release!(queue)end
mem_before = Base.gc_bytes()
for i in 1:100000 leaky()end
gc()
gc() //Just to make sure
mem_after = Base.gc_bytes()
println("Memory leaked $((mem_after-mem_before)/1024/100000) kB per step")
function leaky() a = Array(Float64, 1024, 1024) a = nothing return nothingend
precompile(leaky, ())
mem_before = Base.gc_bytes()
leaky()
gc(); gc(); gc()
mem_after = Base.gc_bytes()
println("Memory leaked $((mem_after-mem_before)/1024) kB")
I reduced it to the minimal leaking case.
Function leaky()
CTX cl.create_some_context()
Return nothing
End
Is there a particular reason why the constructors of context set the retain to true? If I set it to false the memory leak goes away. Apparently there are platforms where the ocl memory can only be freed iff the reference count of all objects is zero. http://bloerg.net/2013/01/15/opencl-resource-management.html
Best,
Valentin