为什么这行代码会泄漏内存?

发布于 2024-11-28 02:31:46 字数 819 浏览 2 评论 0原文

我发现我的项目中有一行代码正在泄漏内存。这是一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

只为一人 2024-12-05 02:31:46

看来 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

恬淡成诗 2024-12-05 02:31:46

可以

clFinish(CommandQueue);

在后面添加

clEnqueueNDRangeKernel

You can add

clFinish(CommandQueue);

after

clEnqueueNDRangeKernel
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文