如何解决私有字节(本机内存)泄漏? [英] How to solve Private bytes (Native memory) leak?
问题描述
我正在开发似乎有泄漏的C#应用程序. 我使用了内存分析器,发现我的
I'm developing a C# application which seems to have a leak. I've used memory profiler and found that my
私有字节继续增加,但所有堆中的字节没有增加,这意味着这可能是本机内存泄漏
private bytes keep increasing but Bytes in all Heaps do not, which means that probably it's a native memory leak
现在我被卡住了,如何找到本机代码中的内存泄漏?
Now I'm stuck, how do I find memory leaks in native code ?
推荐答案
首先,如果您有泄漏过程的转储,则可以在WinDbg中打开它并发出命令: !address -summary
First, if you have a dump of the leaking process, you can open it in WinDbg and issue the command : !address -summary
- 如果RegionUsageHeap大,则应该是本机内存泄漏
- 如果RegionUsageIsVAD,则应该是.NET内存泄漏.
如果这是本机泄漏,那么您有2个选择:
If this is a native leak, then you have 2 options :
-
使用DebugDiag:出现提示时,选择本机内存泄漏和处理泄漏",选择要诊断的过程,然后开始使用该应用程序,直到尝试进行内存泄漏为止.完成后,生成应用程序的完整转储(右键单击泄漏规则,然后选择完整用户转储").然后,您可以分析生成的转储(您需要正确配置符号才能使其有效运行):在高级分析"选项卡上,选择内存压力分析器",打开转储文件,然后按开始分析".这将产生一个HTML报告,您可以对其进行分析.您可以参考此使用应用程序验证程序/WinDbg.在应用程序验证程序中,选择您的应用程序(.exe).在测试"页面中,确保选择了基础/堆".在下部窗格中,确保将迹线"设置为true.保存配置后,请在泄漏发生时重新运行应用程序并生成完整转储.转储生成后,请不要忘记清除应用程序标志.然后,您可以从WinDbg中打开转储,并借助'!heap'命令调查泄漏.特别是'!heap -l'将为您提供泄漏块的列表,'!heap -p -a'将显示块的详细信息,包括分配的调用堆栈.
Use Application Verifier / WinDbg. In application verifier, select your application (.exe). In tests page, be sure Basics/Heaps is selected. In the lower pane, be sure 'Traces' is set to true. Once the configuration saved, re-run the application and generate a full dump when the leak occurs. Don't forget to clean application flags after the dump is generated. Then you can open the dump from within WinDbg, and investigate the leak with the help of '!heap' command. In particular, '!heap -l' will give you a list of leaked blocks, '!heap -p -a ' will show the details of a block, including the call stack of allocation.
如果这是.NET泄漏,则可以使用第三方工具进行故障排除.从1.2版开始,DebugDiag还可以执行.NET内存泄漏分析(但是,从未尝试过这样做).
If this is a .NET leak, there are third party tools to troubleshoot it. Starting from version 1.2, DebugDiag is also enable to perform .NET memory leak analysis (never tried this however).
这篇关于如何解决私有字节(本机内存)泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!