debug

1, check handle leak.

Use Lua script to search the codes.

 

2, check memory leak.

If you use CRT, you could use:

_CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF);
//_CrtSetBreakAlloc(182366);

// http://msdn.microsoft.com/en-US/library/e5ewb1h3(VS.80).aspx

 

3, get performance data.

We could use PDH functions. CPDHData

 

4, 注释代码隔离问题。

 

5,

1. 加一个对象计数器, 哪种对象一直增加, 就是它了.
2. 申请比较多的类, 轮流内部增加一个 char buffer[65536], 看看内存增加是否加快, 很快就可以找出了.

 

6, VLD boundchecker ADPlus WinDbg SysInternals-Tools (handle)

 

7, OANOCACHE=1
http://msdn.microsoft.com/en-us/library/ms221105.aspx
For example, if the application allocates a BSTR and frees it, the free block of memory is put into the BSTR cache by Automation. If the application then allocates another BSTR, it can get the free block from the cache. If the second BSTR allocation is not freed, IMallocSpy will attribute the leak to the first allocation of the BSTR. You can determine the correct source of the leak (the second allocation) by disabling the BSTR caching using the debug version of Oleaut32.dll, and by setting the environment variable OANOCACHE=1 before running the application.

8, some tools Mozilla uses:

http://www.mozilla.org/performance/tools.html

9, 启用或禁用内存诊断可以调用全局函数 AfxEnableMemoryTracking()

#ifdef _DEBUG
    CMemoryState oldMemState, newMemState, diffMemState;
    oldMemState.Checkpoint();
#endif
     ...
 (被测试的代码)
     ...
#ifdef _DEBUG
    newMemState.Checkpoint();
   if(diffMemState.Difference(oldMemState, newMemState))    {
        TRACE(“Memory Leaked Here:\n\n" );
    }
#endif
posted @   林志玲  阅读(311)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
点击右上角即可分享
微信分享提示