Lu4
Lu4

Reputation: 15032

Why is this line of code leaks memory?

I have found a line of code that is leaking memory in my project. It's a DllImport method:

[DllImport("OpenCL")] public static extern Error clEnqueueNDRangeKernel(OpenCLCommandQueue command_queue, OpenCLKernel kernel, Int32 work_dim, [In] IntPtr[] global_work_offset, [In] IntPtr[] global_work_size, [In] IntPtr[] local_work_size, Int32 num_events_in_wait_list, [In] OpenCLEvent[] event_wait_list, out OpenCLEvent e);

It is called with this code:

OpenCLEvent e;

OpenCLDriver.clEnqueueNDRangeKernel(CommandQueue.OpenCLCommandQueue, OpenCLKernel, globalWorkSize.Length, globalWorkOffset, globalWorkSize, localWorkSize, eventWaitList.Count, eventWaitList.OpenCLEventArray, out e);

return null;

Things such as CommandQueue.OpenCLCommandQueue and other arguments are ordinary properties or variables which can't leak memory, there are no code behind them.

I don't understand how can clEnqueueNDRangeKernel call leak memory? Am I missing something?

Upvotes: 0

Views: 419

Answers (2)

Ingo
Ingo

Reputation: 5381

You can add

clFinish(CommandQueue);

after

clEnqueueNDRangeKernel

Upvotes: 0

Yahia
Yahia

Reputation: 70369

it seems that there was a memory leak problem in OpenCL with clEnqueueNDRangeKernel known since 2009, fixed 2010...

http://www.opentk.com/node/1541?page=3
http://forums.amd.com/devforum/messageview.cfm?catid=390&threadid=122161&highlight_key=y

Upvotes: 2

Related Questions