What can cause section handle leaks?

北城余情 提交于 2019-12-18 05:54:08

问题


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.


回答1:


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.




回答2:


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.




回答3:


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).




回答4:


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()


来源:https://stackoverflow.com/questions/7846526/what-can-cause-section-handle-leaks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!