码迷,mamicode.com
首页 > 其他好文 > 详细

Detected memory leaks! Dumping objects

时间:2014-11-24 10:03:55      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:detected memory leak

Detected memory leaks!
Dumping objects ->
{563} normal block at 0x0FAF4D60, 255 bytes long.
 Data: <SD-20140120MYGT > 53 44 2D 32 30 31 34 30 31 32 30 4D 59 47 54 00 

mfc 获取局域网Ip上次有内存溢出,我来说说解决办法!


方法:_CrtSetBreakAlloc(563); // 最好在你内存分配的前面加上内存溢出的行号;

快捷键:shift+F11 进行调试找到你内存溢出的位置进行修改即可!

下面就以我代码例子如下:(我的主要问题在于,使用了cstring 转 char 的转换函数,内存分配了,并未进行 delete [])

_CrtSetBreakAlloc(556);
	m_devIpShow.DeleteAllItems();
	hThread = (HANDLE)_beginthreadex(NULL, 0, &SecondThreadFunc, NULL, 0, NULL);
	WaitForSingleObject( hThread, INFINITE );  
	CloseHandle(hThread);</span>

跳转

extern "C" _CRTIMP void * __cdecl _malloc_dbg (
        size_t nSize,
        int nBlockUse,
        const char * szFileName,
        int nLine
        )
{
        void *res = _nh_malloc_dbg(nSize, _newmode, nBlockUse, szFileName, nLine);
        RTCCALLBACK(_RTC_Allocate_hook, (res, nSize, 0));
        return res;
}

跳转

void* __cdecl operator new[](size_t nSize)
{
	return ::operator new(nSize);
}

void __cdecl operator delete[](void* p)
{
	::operator delete(p);
}

跳转

<span style="color:#362e2b;">//------------------cstring 转 string 
char* zhuanhuan(std::string src) 
{
	char *dst = new char[255];
	int i; 
	int j=src.length();
	for(i=0;i <src.length();i++) 
		dst[i]=src[i]; 
	dst[i] = '\0';
	return dst;
}</span>

可以声明一个全局的变量,使用以后进行delete 得已解决!



Detected memory leaks! Dumping objects

标签:detected memory leak

原文地址:http://blog.csdn.net/u010236550/article/details/41440021

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!