为什么这行代码会泄漏内存?
我发现我的项目中有一行代码正在泄漏内存。这是一个 DllImport 方法:
[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);
使用以下代码调用它:
OpenCLEvent e;
OpenCLDriver.clEnqueueNDRangeKernel(CommandQueue.OpenCLCommandQueue, OpenCLKernel, globalWorkSize.Length, globalWorkOffset, globalWorkSize, localWorkSize, eventWaitList.Count, eventWaitList.OpenCLEventArray, out e);
return null;
CommandQueue.OpenCLCommandQueue 等参数和其他参数都是普通属性或变量,不会泄漏内存,它们后面没有代码。
我不明白 clEnqueueNDRangeKernel 如何调用泄漏内存?我错过了什么吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来 OpenCL 中存在内存泄漏问题,自 2009 年以来已知
clEnqueueNDRangeKernel
,并于 2010 年修复...http://www.opentk.com/node/1541?page=3
http://forums.amd.com/devforum/messageview.cfm?catid=390&threadid=122161&highlight_key=y
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
可以
在后面添加
You can add
after