什么会导致部分手柄泄漏?

发布于 2024-12-11 04:28:20 字数 400 浏览 0 评论 0原文

这是我之前的问题的后续问题。

这个回答我之前的问题,我使用 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 技术交流群。

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

发布评论

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

评论(4

赏烟花じ飞满天 2024-12-18 04:28:20

引用 Mark Russinovich 的 Inside Windows 2000(现在称为 Windows Internals),

节对象(Win32 子系统将其称为文件映射对象)表示两个或多个进程可以共享的内存块。

所以,它是一个内存映射文件。如果您创建了内存映射文件并且无法关闭它,它们就会泄漏。很难说得更具体。

Quoting Mark Russinovich's Inside Windows 2000 (what is now called Windows Internals),

The section object, which the Win32 subsystem calls a file mapping object, represents a block of memory that two or more processes can share.

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.

故人的歌 2024-12-18 04:28:20

事实证明,问题出在计算当前进程的线程数的低级函数中。该函数使用了

CreateToolhelp32Snapshot

返回句柄的 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

CreateToolhelp32Snapshot

API function which returns a handle, which was not closed properly. I am not sure why this produces a section handle leak though.

盗心人 2024-12-18 04:28:20

不与文件句柄关联的内存映射文件可用于 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 corresponding CloseHandle() in all your source code (including third-party source).

好听的两个字的网名 2024-12-18 04:28:20

.net 中的节句柄泄漏是由于 Microsoft 修补程序 KB2670838 造成的。
卸载此更新,部分句柄泄漏问题(内存不足)将得到修复。

Parameter is not valid. at System.Drawing.Image.get_Width()
at System.Drawing.Image.get_Size()

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.

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