Visual 2010 界面库的内存泄漏问题

jump0371 2012-03-13 11:47:31
我使用Visual 2010中的最新的界面库(仿Visual Studio风格)编写程序,打开程序,直接关闭程序,Visual 2010就检测到有内存泄漏,提示如下:
Detected memory leaks!
Dumping objects ->

。。。。。。。。。。。。。
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {132} normal block at 0x01346FC8, 19 bytes long.
Data: <T y > 54 CD 07 79 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {131} normal block at 0x01346F70, 26 bytes long.
Data: <T y > 54 CD 07 79 09 00 00 00 09 00 00 00 01 00 00 00
Object dump complete.
通过检测dbgheap.c中的new的过程,在“
/* break into debugger at specific memory allocation */
if (_crtBreakAlloc != -1L && lRequest == _crtBreakAlloc)
_CrtDbgBreak();
设置断点,发现这些内存泄漏的地方全部是和界面上的pane、toolbar等相关的静态变量,如{131} block的调用栈是这样的:


> msvcr100d.dll!_heap_alloc_dbg_impl(unsigned int nSize, int nBlockUse, const char * szFileName, int nLine, int * errno_tmp) 行 392
C++
msvcr100d.dll!_nh_malloc_dbg_impl(unsigned int nSize, int nhFlag, int nBlockUse, const char * szFileName, int nLine, int * errno_tmp) 行 239 + 0x19 字节
C++
msvcr100d.dll!_nh_malloc_dbg(unsigned int nSize, int nhFlag, int nBlockUse, const char * szFileName, int nLine) 行 302 + 0x1d 字节
C++
msvcr100d.dll!_malloc_dbg(unsigned int nSize, int nBlockUse, const char * szFileName, int nLine) 行 160 + 0x1b 字节
C++
mfc100d.dll!CAfxStringMgr::Allocate(int nChars, int nCharSize) 行 156 + 0x16 字节
C++
mfc100d.dll!ATL::CSimpleStringT<char,1>::Fork(int nLength) 行 809 + 0x26 字节
C++
mfc100d.dll!ATL::CSimpleStringT<char,1>::PrepareWrite2(int nLength) 行 849 + 0xc 字节
C++
mfc100d.dll!ATL::CSimpleStringT<char,1>::PrepareWrite(int nLength) 行 838
C++
mfc100d.dll!ATL::CSimpleStringT<char,1>::GetBuffer(int nMinBufferLength) 行 535
C++
mfc100d.dll!ATL::CSimpleStringT<char,1>::SetString(const char * pszSrc, int nLength) 行 654 + 0xc 字节
C++
mfc100d.dll!ATL::CSimpleStringT<char,1>::SetString(const char * pszSrc) 行 629
C++
mfc100d.dll!ATL::CSimpleStringT<char,1>::operator=(const char * pszSrc) 行 342
C++
mfc100d.dll!ATL::CStringT<char,StrTraitMFC_DLL<char,ATL::ChTraitsCRT<char> > >::operator=(const char * pszSrc) 行 1235
C++
mfc100d.dll!ATL::CStringT<char,StrTraitMFC_DLL<char,ATL::ChTraitsCRT<char> > >::CStringT<char,StrTraitMFC_DLL<char,ATL::ChTraitsCRT<char> > >(const char * pszSrc) 行 968
C++
mfc100d.dll!`dynamic initializer for 'strBaseControlBarProfile''() 行 44 + 0x14 字节
C++
msvcr100d.dll!_initterm(void (void)* * pfbegin, void (void)* * pfend) 行 873
C
mfc100d.dll!_CRT_INIT(void * hDllHandle, unsigned long dwReason, void * lpreserved) 行 284 + 0xf 字节
C
mfc100d.dll!__DllMainCRTStartup(void * hDllHandle, unsigned long dwReason, void * lpreserved) 行 506 + 0x11 字节
C
mfc100d.dll!_DllMainCRTStartup(void * hDllHandle, unsigned long dwReason, void * lpreserved) 行 476 + 0x11 字节
C


双击“mfc100d.dll!`dynamic initializer for 'strBaseControlBarProfile''() 行 44 + 0x14 字节
C++“
定位到afxbasepane.cpp中如下行:
static const CString strBaseControlBarProfile = _T("BasePanes");


类似的,其他的内存泄漏的地方都是这些静态变量的地方。感觉很困惑,这些都是静态变量,而且又不是new出来的,为什么有内存泄漏呢?


试了下VC的sample,就没有这种内存泄漏提示。


谢谢大家。
...全文
254 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
向立天 2013-03-02
  • 打赏
  • 举报
回复
您好 我是本版版主 此帖已多日无人关注 请您及时结帖 如您认为问题没有解决可按无满意结帖处理 另外本版设置了疑难问题汇总帖 并已在版面置顶 相关规定其帖子中有说明 您可以根据规定提交您帖子的链接 如您目前不想结帖只需回帖说明 我们会删除此结帖通知 见此回复三日内无回应 我们将强制结帖 相关规定详见界面界面版关于版主结帖工作的具体办法
罗平 2012-03-13
  • 打赏
  • 举报
回复
退出不要使用 exit ,要安全退出。
LiuYinChina 2012-03-13
  • 打赏
  • 举报
回复
_crtBreakAlloc(131);
_crtBreakAlloc(132);
hdg3707 2012-03-13
  • 打赏
  • 举报
回复
要不然你重新生成一个工程,先不要加任何东西,直接编绎并运行,看看是否有内存泄露,如果没有,再加一点,再编绎运行.重复这么做,看看加到哪块出问题.
有时候VC出现莫名其妙的问题却无法解决,就用这种方法来试试着解决,有时候就没问题了,可能是编绎选项不一样

15,976

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧