什么会导致部分手柄泄漏?
如这个回答我之前的问题,我使用 ProcessExplorer 来分析我的应用程序用来查找句柄泄漏的句柄列表。
泄漏的句柄属于 Section 类型。
节句柄到底是什么、它在哪里使用以及什么会导致节句柄泄漏?
我没有在代码中使用内存映射文件。
This is a follow-up question to my previous question.
As suggested in this answer to my previous question, I used ProcessExplorer to analyze a list of handles that my application is using to find a handle leak.
The handles that are leaking are of type Section.
What exactly is a section handle, where is it used and what can cause section handles to leak?
I'm not using memory mapped files in my code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
引用 Mark Russinovich 的 Inside Windows 2000(现在称为 Windows Internals),
所以,它是一个内存映射文件。如果您创建了内存映射文件并且无法关闭它,它们就会泄漏。很难说得更具体。
Quoting Mark Russinovich's Inside Windows 2000 (what is now called Windows Internals),
So, it's a memory mapped file. They'd leak if you created a memory mapped file and failed to close it. Pretty hard to be much more specific.
事实证明,问题出在计算当前进程的线程数的低级函数中。该函数使用了
返回句柄的 API 函数,该句柄未正确关闭。我不确定为什么这会产生部分句柄泄漏。
It turns out that the problem was in a low-level function that counts the number of threads of the current process. This function used the
API function which returns a handle, which was not closed properly. I am not sure why this produces a section handle leak though.
不与文件句柄关联的内存映射文件可用于 IPC(进程间通信)。如果您不直接使用它们,则可能您的某个单元或组件正在执行某些 IPC 通信。很可能你使用一个组件连接到另一个进程,并且没有按照请求释放它。
首先要采取的措施是跟踪任何内存泄漏(使用 FastMM4 调试模式),您肯定会在代码中找到一些未释放的对象。
由于句柄通常是由对象分配的,根据我的实验,解决所有内存泄漏将解决句柄泄漏。
如果您没有任何内存泄漏,则存在一些
CreateFileMapping()
调用来检查所有源代码(包括第三方)中是否有相应的CloseHandle()
来源)。A memory mapped file not associated with a file handle can be used for IPC (communication between process). If you do not use them directly, perhaps one of your unit or component is doing some IPC communication. It is very likely that you use a component to connect to another process, and do not release it as requested.
First action to be taken is to track for any memory leak (using FastMM4 debug mode), and you'll certainly find some un-released objects in your code.
Since handles are commonly allocated by objects, from my experiment, resolving all memory leaks will resolve handle leaks.
If you do not have any memory leak, there is some
CreateFileMapping()
calls to check for a correspondingCloseHandle()
in all your source code (including third-party source)..net 中的节句柄泄漏是由于 Microsoft 修补程序 KB2670838 造成的。
卸载此更新,部分句柄泄漏问题(内存不足)将得到修复。
The section handle leak in .net is due to the Microsoft Hotfix KB2670838.
Uninstall this update and the section handle leak issue (Out of Memory) will be fixed.