Detected memory leaks! Dumping objects

来源:互联网 发布:安卓跑分软件 编辑:程序博客网 时间:2024/06/06 02:02
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);}

跳转

//------------------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 得已解决也可以在创建线程,把地址空间传参数!(
当跳转到你自己写的代码,就行了哈!说明找到问题了)



3 0