使用MFC提供的功能来检测内存泄露。

使用方法:

1)工程是MFC工程,或是工程的设置中有Use MFC in a Shared DLL,
2)很多地方说是要定义以下宏
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
但是我发现只要include <afx.h> 即可。(大家可以检测一下)
3)可以在F5运行程序后,在output窗口中看到如下的内存泄露的显示。(只在debug下有用哦)
4)如果有泄露,则显示如下:
Detected memory leaks!
Dumping objects ->
{214} normal block at 0x00D91618, 4 bytes long.
 Data: <    > 00 00 00 00
{208} normal block at 0x00D914D0, 4 bytes long.
 Data: <    > 00 00 00 00
{207} normal block at 0x00D91490, 4 bytes long.
 Data: <    > D0 14 D9 00
{205} normal block at 0x00D91410, 4 bytes long.
 Data: <    > 00 00 00 00
{204} normal block at 0x003AFFD8, 4 bytes long.
 Data: <    > 10 14 D9 00
{203} normal block at 0x003AFF98, 4 bytes long.
 Data: <    > 00 00 00 00
{202} normal block at 0x003AFF58, 4 bytes long.
 Data: <  : > 98 FF 3A 00
{200} normal block at 0x003AFF18, 4 bytes long.
 Data: <    > 00 00 00 00
Object dump complete.

相关文章:

  • 2021-06-29
  • 2021-07-01
  • 2021-09-20
  • 2021-07-27
  • 2021-12-05
  • 2022-12-23
  • 2021-09-27
猜你喜欢
  • 2022-01-03
  • 2021-08-04
  • 2021-05-19
  • 2021-11-18
  • 2021-10-21
  • 2021-08-20
  • 2021-06-24
相关资源
相似解决方案