vc不包含MFC就不打印内存泄露?
2013-03-21 01:48
274 查看
无聊写了段测试代码,发现一个很费解的地方,下面这段代码是没有包含MFC的:
然后程序结束的时候并没有在输出面板打印内存泄露。如下图:
如果程序包含了MFC,例如:
那结果就不一样了,输出面板打印了内存泄露的信息:
经过测试发现:如果程序包含了<afxwin.h>,那么程序结束时会在输出面板打印内存泄露信息,否则就不打印了。。。
#include "stdafx.h" struct stTest { int a; int b; char szTest[32]; stTest() { a = 1; b = 2; sprintf(szTest, "abc"); } }; int _tmain(int argc, _TCHAR* argv[]) { stTest* p = new stTest; printf("a = %d, b = %d, c = %s\n", p->a, p->b, p->szTest); getchar(); return 0; }
然后程序结束的时候并没有在输出面板打印内存泄露。如下图:
如果程序包含了MFC,例如:
#include "stdafx.h" #include "statci_new_test2.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // 唯一的应用程序对象 CWinApp theApp; using namespace std; struct stTest { int a; int b; char szTest[32]; stTest() { a = 1; b = 2; sprintf(szTest, "abc"); } }; int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { int nRetCode = 0; // 初始化 MFC 并在失败时显示错误 if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) { // TODO: 更改错误代码以符合您的需要 _tprintf(_T("致命错误: MFC 初始化失败\n")); nRetCode = 1; } else { // TODO: 在此处为应用程序的行为编写代码。 static stTest* p = new stTest; printf("a = %d, b = %d, c = %s\n", p->a, p->b, p->szTest); getchar(); } return nRetCode; }
那结果就不一样了,输出面板打印了内存泄露的信息:
经过测试发现:如果程序包含了<afxwin.h>,那么程序结束时会在输出面板打印内存泄露信息,否则就不打印了。。。
相关文章推荐
- VC 2010+MFC:CMFCVisualManager::GetInstance()导致的内存泄露 2012-2-15 10:18
- MFC工程检测内存泄露方法
- MFC/VC: 关于内存问题。
- 关于DLL工程中存在全局变量可能导致MFC内存泄露误报的原因分析及解决办法
- 关于MFC下检查和消除内存泄露的技巧
- 使用VC++检查内存泄露(不懂)
- [转]VC/MFC 基于对话框的图片拖动(利用内存DC防止图片闪烁)
- 使用VC/MFC打印(Print)
- 浅谈MFC内存泄露检测与内存访问越界检测机制
- 如何检测非MFC程序的内存泄露?
- 检查MFC程序的内存泄露
- 内存泄露打印new和delete重载
- MFC内存泄露检测
- 检查MFC程序的内存泄露
- VC中检测内存泄露的代码
- 内存泄露(包含循环引用)和野指针(僵尸对象)
- MFC环境osgEarth开发程序内存泄露的解决办法
- mfc框架下osg的内存泄露问题(转)
- vc下内存泄露检测工具
- 卸载MFC DLL时出现内存泄露