unbounded_buffer、_CrtSetDbgFlag 和内存泄漏
我正在尝试使用新功能之一 - 异步代理库。我刚刚添加了一个
unbounded_buffer m_myDataBuffer; 对于我的 C++ 类,仅此而已 - 尚未运行代理。
为了在我的应用程序中启用内存泄漏检测,我正在使用:
#ifdef _DEBUG
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
但是在关闭应用程序窗口后(我使用简单的 Win 32 GUI 应用程序),Visual Studio 显示了一堆内存泄漏:
Detected memory leaks!
Dumping objects ->
{261} normal block at 0x007C4EB8, 288 bytes long.
Data: < 5 > 00 00 02 00 02 00 00 00 10 02 00 00 10 B1 35 00
{260} normal block at 0x007C4E70, 12 bytes long.
Data: < HM| > 00 00 00 00 00 02 00 00 48 4D 7C 00
{259} normal block at 0x007C4E18, 28 bytes long.
Data: < > 00 00 00 00 CD CD CD CD 00 00 00 00 00 00 00 00
{258} normal block at 0x0035AEF0, 28 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
{257} normal block at 0x007C4D48, 144 bytes long.
Data: < U > A4 C2 F4 55 CD CD CD CD 00 00 00 00 00 00 00 00
{255} normal block at 0x007C0AB8, 16388 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
{254} normal block at 0x0035CF30, 12 bytes long.
Data: < | > 01 10 00 00 01 00 00 00 B8 0A 7C 00
{253} normal block at 0x007C0978, 256 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
{252} normal block at 0x007C08A8, 148 bytes long.
Data: < ! U > 8C 21 F5 55 01 00 00 00 00 00 00 00 00 00 00 00
{251} normal block at 0x0035FEB8, 256 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
{250} normal block at 0x0035FDE8, 148 bytes long.
Data: < ! U > 8C 21 F5 55 01 00 00 00 00 00 00 00 00 00 00 00
{249} normal block at 0x007C0068, 2048 bytes long.
Data: < 5 > A0 FD 35 00 CD CD CD CD CD CD CD CD CD CD CD CD
{248} normal block at 0x0035FDA0, 12 bytes long.
Data: <` 5 > 60 F9 35 00 00 00 00 00 FF FF FF FF
{247} normal block at 0x0035F960, 1024 bytes long.
Data: < 5 | > E8 FD 35 00 A8 08 7C 00 00 00 00 00 00 00 00 00
{246} normal block at 0x0035F8B8, 104 bytes long.
Data: < 5 5 > 10 B1 35 00 98 D0 35 00 02 00 00 00 02 00 00 00
{245} normal block at 0x0035F078, 2048 bytes long.
Data: <0 5 > 30 F0 35 00 CD CD CD CD CD CD CD CD CD CD CD CD
{244} normal block at 0x0035F030, 12 bytes long.
Data: < 5 > F0 EB 35 00 00 00 00 00 FF FF FF FF
{243} normal block at 0x0035EBF0, 1024 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
{242} normal block at 0x0035E3B0, 2048 bytes long.
Data: <h 5 > 68 E3 35 00 CD CD CD CD CD CD CD CD CD CD CD CD
{241} normal block at 0x0035E368, 12 bytes long.
Data: <( 5 > 28 DF 35 00 00 00 00 00 FF FF FF FF
{240} normal block at 0x0035DF28, 1024 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
{239} normal block at 0x0035DE08, 224 bytes long.
Data: < U 5 > 98 13 F5 55 00 00 00 00 0C DE 35 00 00 00 00 00
{238} normal block at 0x0035D5C8, 2048 bytes long.
Data: < 5 > 80 D5 35 00 CD CD CD CD CD CD CD CD CD CD CD CD
{237} normal block at 0x0035D580, 12 bytes long.
Data: <@ 5 > 40 D1 35 00 00 00 00 00 FF FF FF FF
{236} normal block at 0x0035D140, 1024 bytes long.
Data: < 5 > 08 DE 35 00 00 00 00 00 00 00 00 00 00 00 00 00
{235} normal block at 0x0035D098, 104 bytes long.
Data: < 5 5 5 > 10 B1 35 00 B8 F8 35 00 08 DE 35 00 CD CD CD CD
{234} normal block at 0x0035D008, 80 bytes long.
Data: <, U\ U > 2C C4 F4 55 5C C1 F4 55 00 00 00 00 00 00 00 00
{233} normal block at 0x0035CF78, 80 bytes long.
Data: <, U\ U > 2C C4 F4 55 5C C1 F4 55 00 00 00 00 00 00 00 00
{231} normal block at 0x0035CEF0, 4 bytes long.
Data: < > 00 00 00 00
{230} normal block at 0x0035CE58, 88 bytes long.
Data: < | 5 > 01 00 00 00 00 00 00 00 01 00 00 00 7C CF 35 00
{229} normal block at 0x0035C300, 44 bytes long.
Data: < > 03 00 00 00 02 00 00 00 02 00 00 00 00 00 00 00
{228} normal block at 0x0035C5E0, 2104 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
{227} normal block at 0x0035C4D0, 208 bytes long.
Data: <l U 5 0 5 > 6C 0A F5 55 00 00 00 00 E8 C0 35 00 30 C1 35 00
{225} normal block at 0x0035C2C0, 4 bytes long.
Data: < 5 > B8 F8 35 00
{224} normal block at 0x0035C280, 4 bytes long.
Data: < 5 > 98 D0 35 00
{223} normal block at 0x0035C200, 64 bytes long.
Data: < 5 > 10 C5 35 00 CD CD CD CD CD CD CD CD CD CD CD CD
{222} normal block at 0x0035C488, 8 bytes long.
Data: < > 00 00 00 00 01 00 00 00
{221} normal block at 0x0035C418, 48 bytes long.
Data: < > 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00
{220} normal block at 0x0035C3D8, 4 bytes long.
Data: < > 00 00 00 00
{219} normal block at 0x0035C378, 36 bytes long.
Data: < > 03 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00
{217} normal block at 0x0035C130, 148 bytes long.
Data: <l U > 6C D7 F4 55 02 00 00 00 01 00 00 00 10 00 00 00
{216} normal block at 0x0035C0E8, 8 bytes long.
Data: < U 5 > C0 11 F5 55 10 B1 35 00
{215} normal block at 0x0035B8A8, 2048 bytes long.
Data: < 5 > 00 AE 35 00 CD CD CD CD CD CD CD CD CD CD CD CD
{214} normal block at 0x0035AE00, 12 bytes long.
Data: <h 5 > 68 B4 35 00 00 00 00 00 FF FF FF FF
{213} normal block at 0x0035B468, 1024 bytes long.
Data: < N| > 18 4E 7C 00 00 00 00 00 00 00 00 00 00 00 00 00
{212} normal block at 0x0035AF50, 36 bytes long.
Data: < > 00 00 00 00 02 00 00 00 01 00 00 00 01 00 00 00
{211} normal block at 0x0035B110, 368 bytes long.
Data: < UP 5 > CC 1D F5 55 50 AF 35 00 00 00 00 00 00 00 00 00
Object dump complete.
在我注释掉
unbounded_buffer<int> m_myDataBuffer;
或之后, 泄漏立即消失注释掉
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
unbounded_buffer 有什么特别之处吗?即使不使用它,我也必须释放它?或者我需要以某种特殊的方式设置 _CrtSetDbgFlag 吗? _CrtSetDbgFlag 是内存泄漏的原因,还是在这种情况下以某种方式创建错误检测并且没有真正的内存泄漏?我在这里缺少什么?
我 100% 确定这些泄漏不是来自我的代码,因为我
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#define new new(_NORMAL_BLOCK,__FILE__, __LINE__)
的 stdafx.h 中也有,所以我的代码中的内存泄漏有文件名和行。但那些 unbounded_buffer 没有这样的信息,所以我想这意味着它们来自代理库。
I am trying to use one of the new features - asynchronous agents library. I just added a
unbounded_buffer m_myDataBuffer;
to my C++ class, nothing more - no agent running yet.
To enable memory leak detection in my application, I am using:
#ifdef _DEBUG
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
But after closing my application window (I am using simple Win 32 GUI application) Visual Studio shows a bunch of memory leaks:
Detected memory leaks!
Dumping objects ->
{261} normal block at 0x007C4EB8, 288 bytes long.
Data: < 5 > 00 00 02 00 02 00 00 00 10 02 00 00 10 B1 35 00
{260} normal block at 0x007C4E70, 12 bytes long.
Data: < HM| > 00 00 00 00 00 02 00 00 48 4D 7C 00
{259} normal block at 0x007C4E18, 28 bytes long.
Data: < > 00 00 00 00 CD CD CD CD 00 00 00 00 00 00 00 00
{258} normal block at 0x0035AEF0, 28 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
{257} normal block at 0x007C4D48, 144 bytes long.
Data: < U > A4 C2 F4 55 CD CD CD CD 00 00 00 00 00 00 00 00
{255} normal block at 0x007C0AB8, 16388 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
{254} normal block at 0x0035CF30, 12 bytes long.
Data: < | > 01 10 00 00 01 00 00 00 B8 0A 7C 00
{253} normal block at 0x007C0978, 256 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
{252} normal block at 0x007C08A8, 148 bytes long.
Data: < ! U > 8C 21 F5 55 01 00 00 00 00 00 00 00 00 00 00 00
{251} normal block at 0x0035FEB8, 256 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
{250} normal block at 0x0035FDE8, 148 bytes long.
Data: < ! U > 8C 21 F5 55 01 00 00 00 00 00 00 00 00 00 00 00
{249} normal block at 0x007C0068, 2048 bytes long.
Data: < 5 > A0 FD 35 00 CD CD CD CD CD CD CD CD CD CD CD CD
{248} normal block at 0x0035FDA0, 12 bytes long.
Data: <` 5 > 60 F9 35 00 00 00 00 00 FF FF FF FF
{247} normal block at 0x0035F960, 1024 bytes long.
Data: < 5 | > E8 FD 35 00 A8 08 7C 00 00 00 00 00 00 00 00 00
{246} normal block at 0x0035F8B8, 104 bytes long.
Data: < 5 5 > 10 B1 35 00 98 D0 35 00 02 00 00 00 02 00 00 00
{245} normal block at 0x0035F078, 2048 bytes long.
Data: <0 5 > 30 F0 35 00 CD CD CD CD CD CD CD CD CD CD CD CD
{244} normal block at 0x0035F030, 12 bytes long.
Data: < 5 > F0 EB 35 00 00 00 00 00 FF FF FF FF
{243} normal block at 0x0035EBF0, 1024 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
{242} normal block at 0x0035E3B0, 2048 bytes long.
Data: <h 5 > 68 E3 35 00 CD CD CD CD CD CD CD CD CD CD CD CD
{241} normal block at 0x0035E368, 12 bytes long.
Data: <( 5 > 28 DF 35 00 00 00 00 00 FF FF FF FF
{240} normal block at 0x0035DF28, 1024 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
{239} normal block at 0x0035DE08, 224 bytes long.
Data: < U 5 > 98 13 F5 55 00 00 00 00 0C DE 35 00 00 00 00 00
{238} normal block at 0x0035D5C8, 2048 bytes long.
Data: < 5 > 80 D5 35 00 CD CD CD CD CD CD CD CD CD CD CD CD
{237} normal block at 0x0035D580, 12 bytes long.
Data: <@ 5 > 40 D1 35 00 00 00 00 00 FF FF FF FF
{236} normal block at 0x0035D140, 1024 bytes long.
Data: < 5 > 08 DE 35 00 00 00 00 00 00 00 00 00 00 00 00 00
{235} normal block at 0x0035D098, 104 bytes long.
Data: < 5 5 5 > 10 B1 35 00 B8 F8 35 00 08 DE 35 00 CD CD CD CD
{234} normal block at 0x0035D008, 80 bytes long.
Data: <, U\ U > 2C C4 F4 55 5C C1 F4 55 00 00 00 00 00 00 00 00
{233} normal block at 0x0035CF78, 80 bytes long.
Data: <, U\ U > 2C C4 F4 55 5C C1 F4 55 00 00 00 00 00 00 00 00
{231} normal block at 0x0035CEF0, 4 bytes long.
Data: < > 00 00 00 00
{230} normal block at 0x0035CE58, 88 bytes long.
Data: < | 5 > 01 00 00 00 00 00 00 00 01 00 00 00 7C CF 35 00
{229} normal block at 0x0035C300, 44 bytes long.
Data: < > 03 00 00 00 02 00 00 00 02 00 00 00 00 00 00 00
{228} normal block at 0x0035C5E0, 2104 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
{227} normal block at 0x0035C4D0, 208 bytes long.
Data: <l U 5 0 5 > 6C 0A F5 55 00 00 00 00 E8 C0 35 00 30 C1 35 00
{225} normal block at 0x0035C2C0, 4 bytes long.
Data: < 5 > B8 F8 35 00
{224} normal block at 0x0035C280, 4 bytes long.
Data: < 5 > 98 D0 35 00
{223} normal block at 0x0035C200, 64 bytes long.
Data: < 5 > 10 C5 35 00 CD CD CD CD CD CD CD CD CD CD CD CD
{222} normal block at 0x0035C488, 8 bytes long.
Data: < > 00 00 00 00 01 00 00 00
{221} normal block at 0x0035C418, 48 bytes long.
Data: < > 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00
{220} normal block at 0x0035C3D8, 4 bytes long.
Data: < > 00 00 00 00
{219} normal block at 0x0035C378, 36 bytes long.
Data: < > 03 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00
{217} normal block at 0x0035C130, 148 bytes long.
Data: <l U > 6C D7 F4 55 02 00 00 00 01 00 00 00 10 00 00 00
{216} normal block at 0x0035C0E8, 8 bytes long.
Data: < U 5 > C0 11 F5 55 10 B1 35 00
{215} normal block at 0x0035B8A8, 2048 bytes long.
Data: < 5 > 00 AE 35 00 CD CD CD CD CD CD CD CD CD CD CD CD
{214} normal block at 0x0035AE00, 12 bytes long.
Data: <h 5 > 68 B4 35 00 00 00 00 00 FF FF FF FF
{213} normal block at 0x0035B468, 1024 bytes long.
Data: < N| > 18 4E 7C 00 00 00 00 00 00 00 00 00 00 00 00 00
{212} normal block at 0x0035AF50, 36 bytes long.
Data: < > 00 00 00 00 02 00 00 00 01 00 00 00 01 00 00 00
{211} normal block at 0x0035B110, 368 bytes long.
Data: < UP 5 > CC 1D F5 55 50 AF 35 00 00 00 00 00 00 00 00 00
Object dump complete.
Leaks go away right after I comment out the
unbounded_buffer<int> m_myDataBuffer;
or after I comment out
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
Is there anything special about unbounded_buffer I have to do to release it even if it is not used? Or do I need to set _CrtSetDbgFlag in some special way? Is _CrtSetDbgFlag the cause of mem leaks or it is somehow creating false detections in this case and there are no real memory leaks? What am I missing here?
I am 100% sure that those leaks do not come from my code because I also have
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#define new new(_NORMAL_BLOCK,__FILE__, __LINE__)
in my stdafx.h so memory leaks from my code have filenames and lines. But those of unbounded_buffer do not have such info, so I guess that means they come from agents library.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我发现 _CRTDBG_LEAK_CHECK_DF 标志会自动调用 _CrtDumpMemoryLeaks();在申请结束时。但似乎事情还没有发生在最后。我删除了 _CRTDBG_LEAK_CHECK_DF 并在 main() 末尾调用 _CrtDumpMemoryLeaks() ,现在它正确报告内存泄漏......我希望如此。
Microsoft MSDN 中也有一个关于 PPL 库中的一些内存泄漏的错误报告,希望他们能够尽快修复它们。
Ok, I found out that _CRTDBG_LEAK_CHECK_DF flag makes automatic call of _CrtDumpMemoryLeaks(); at the end of application. But it seems it is happening not at the very end. I removed _CRTDBG_LEAK_CHECK_DF and called _CrtDumpMemoryLeaks() at the end of main() and now it reports memory leaks correctly ... I hope so.
Also there is a bug report in Microsoft MSDN about some memory leaks in PPL libraries, hope they'll fix them soon.