我有一个很大的内存泄漏,我需要一些帮助来找出它的来源。首先,关于代码的一些理论:
这是一个 Kinect 项目。它是在 MS Visual Studio 2012 中构建的 MFC 项目,它使用 Direct2D 将图像放在屏幕上。当我从 Kinect 1 切换到 Kinect 2 时会出现此问题。然后重建除“主”对象之外的每个对象(解构/释放并设置为 NULL(如果指针))。这包括:
- 所有 Direct2D 对象(工厂、渲染目标、位图、画笔、一切)
- 带有线程的 Kinect 面部跟踪器
- 带有线程的 kinect 对象。
对于每个 new 关键字,我在析构函数中使用了 delete 关键字(所以我没有做任何事情来破坏没有用 new 初始化的指针)。我关闭了所有线程处理程序并将它们设置为 NULL。
现在我有内存泄漏,我需要一些帮助才能找到它。我从使用MS MFC 工具开始
初始化后我有一些输出:
Dumping objects ->
{402} normal block at 0x1531E8F0, 28 bytes long.
Data: << @ > 3C 07 06 00 F0 00 00 00 40 01 00 00 00 05 00 00
{401} normal block at 0x152F6CD8, 96 bytes long.
Data: < > > 00 CD CD CD 3E 07 06 00 D0 04 00 00 D8 17 00 00
{400} normal block at 0x03EA0040, 1229064 bytes long.
Data: <R E, > 52 07 06 00 B8 A9 13 00 D0 87 D0 00 18 45 2C 15
{396} normal block at 0x152C9EA0, 20 bytes long.
Data: < > 80 F9 89 00 01 00 00 00 01 00 00 00 01 00 00 00
c:\users\work\documents\github\kinectmain\testmfc\main.cpp(148) : {305} client block at 0x152CF618, subtype c0, 8 bytes long.
a CFont object at $152CF618, 8 bytes long
{295} normal block at 0x152CFC20, 24 bytes long.
Data: <X ( , X > 58 07 CC 00 28 F8 2C 15 58 07 CC 00 00 00 CD CD
{284} normal block at 0x152CF828, 24 bytes long.
Data: <X X , > 58 07 CC 00 58 07 CC 00 20 FC 2C 15 01 00 CD CD
{206} normal block at 0x00CD0588, 12 bytes long.
Data: < @ > B0 04 CD 00 40 05 CD 00 B8 A9 13 00
{205} normal block at 0x00CD0540, 12 bytes long.
Data: < > 88 05 CD 00 B0 04 CD 00 18 BE 13 00
{204} normal block at 0x00CD04F8, 8 bytes long.
Data: < > EC F3 89 00 00 00 00 00
{203} normal block at 0x00CD04B0, 12 bytes long.
Data: <@ > 40 05 CD 00 88 05 CD 00 CD CD CD CD
{202} normal block at 0x00CD0468, 12 bytes long.
Data: < H > 08 FE CC 00 48 A5 CC 00 18 BE 13 00
{201} normal block at 0x00CCFE08, 12 bytes long.
Data: <H h > 48 A5 CC 00 68 04 CD 00 B8 A9 13 00
{200} normal block at 0x00CCA590, 8 bytes long.
Data: < > FC A4 CC 00 00 00 00 00
{199} normal block at 0x00CCA548, 12 bytes long.
Data: <h > 68 04 CD 00 08 FE CC 00 CD CD CD CD
c:\users\work\documents\github\kinectmain\testmfc\main.cpp(163) : {198} normal block at 0x00CCA4F8, 16 bytes long.
Data: <R H > 52 07 06 00 90 A5 CC 00 48 A5 CC 00 02 00 00 00
{188} normal block at 0x00CC07B0, 8 bytes long.
Data: < > 9C FB A1 00 00 00 00 00
{187} normal block at 0x00CC0758, 24 bytes long.
Data: <( , ( , , > 28 F8 2C 15 28 F8 2C 15 20 FC 2C 15 01 01 CD CD
Object dump complete.
0 bytes in 0 Free Blocks.
1229392 bytes in 17 Normal Blocks.
13498 bytes in 73 CRT Blocks.
0 bytes in 0 Ignore Blocks.
8 bytes in 1 Client Blocks.
Largest number used: 1245916 bytes.
Total allocations: 2504946 bytes.
在 kinect 切换之后:
Dumping objects ->
{961} normal block at 0x1531E8F0, 28 bytes long.
Data: << @ > 3C 07 06 00 F0 00 00 00 40 01 00 00 00 05 00 00
{960} normal block at 0x1534A658, 96 bytes long.
Data: < > p > 00 CD CD CD 3E 07 06 00 70 05 00 00 A8 15 00 00
{959} normal block at 0x03EA0040, 1229064 bytes long.
Data: <R , 4 > 52 07 06 00 18 BE 13 00 90 F1 2C 15 98 9B 34 15
{956} normal block at 0x152CBFD0, 20 bytes long.
Data: < > 80 F9 89 00 01 00 00 00 01 00 00 00 01 00 00 00
c:\users\work\documents\github\kinectmain\testmfc\main.cpp(148) : {305} client block at 0x152CF618, subtype c0, 8 bytes long.
a CFont object at $152CF618, 8 bytes long
{295} normal block at 0x152CFC20, 24 bytes long.
Data: <X ( , X > 58 07 CC 00 28 F8 2C 15 58 07 CC 00 00 00 CD CD
{284} normal block at 0x152CF828, 24 bytes long.
Data: <X X , > 58 07 CC 00 58 07 CC 00 20 FC 2C 15 01 00 CD CD
{206} normal block at 0x00CD0588, 12 bytes long.
Data: < @ > B0 04 CD 00 40 05 CD 00 B8 A9 13 00
{205} normal block at 0x00CD0540, 12 bytes long.
Data: < > 88 05 CD 00 B0 04 CD 00 18 BE 13 00
{204} normal block at 0x00CD04F8, 8 bytes long.
Data: < > EC F3 89 00 00 00 00 00
{203} normal block at 0x00CD04B0, 12 bytes long.
Data: <@ > 40 05 CD 00 88 05 CD 00 CD CD CD CD
{202} normal block at 0x00CD0468, 12 bytes long.
Data: < H > 08 FE CC 00 48 A5 CC 00 18 BE 13 00
{201} normal block at 0x00CCFE08, 12 bytes long.
Data: <H h > 48 A5 CC 00 68 04 CD 00 B8 A9 13 00
{200} normal block at 0x00CCA590, 8 bytes long.
Data: < > FC A4 CC 00 00 00 00 00
{199} normal block at 0x00CCA548, 12 bytes long.
Data: <h > 68 04 CD 00 08 FE CC 00 CD CD CD CD
c:\users\work\documents\github\kinectmain\testmfc\main.cpp(163) : {198} normal block at 0x00CCA4F8, 16 bytes long.
Data: <R H > 52 07 06 00 90 A5 CC 00 48 A5 CC 00 02 00 00 00
{188} normal block at 0x00CC07B0, 8 bytes long.
Data: < > 9C FB A1 00 00 00 00 00
{187} normal block at 0x00CC0758, 24 bytes long.
Data: <( , ( , , > 28 F8 2C 15 28 F8 2C 15 20 FC 2C 15 01 01 CD CD
Object dump complete.
0 bytes in 0 Free Blocks.
1229392 bytes in 17 Normal Blocks.
13498 bytes in 73 CRT Blocks.
0 bytes in 0 Ignore Blocks.
8 bytes in 1 Client Blocks.
Largest number used: 1245916 bytes.
Total allocations: 3742634 bytes.
所以总分配量从 2504946 字节增加到 3742634 字节,但没有其他变化。
此外,每次开关我都会收到以下错误:
calling DestroyWindow in CWnd::~CWnd; OnDestroy or PostNcDestroy in derived class will not be called.
即使在程序关闭之前我不会调用destroyWindow。
关于可能是什么原因或我可以使用什么工具来查找原因的任何提示、建议或提示都会很棒。