DWORD WINAPI ProcDemo(LPVOID lpParam)
{
char* sReturn[20];
for(int i=0;i<20;i++)
{
sReturn[i]=new char[60];
memset(sReturn[i],0,60);
}
int n=0;
while (TRUE)
{
TRACE("%d\r\n",n++);
Sleep(2000);
continue;
}
return 0L;
}上面的函数被启动为一个线程CreateThread(NULL,0,ProcDemo,this,0,&dwThreadID);
但程序关闭时,来个一堆这个东西
Detected memory leaks!
Dumping objects ->
D:\Palmtime\Test\TestDoc.cpp(91) : {120} normal block at 0x003463F0, 60 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
D:\Palmtime\Test\TestDoc.cpp(91) : {119} normal block at 0x00346378, 60 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
D:\Palmtime\Test\TestDoc.cpp(91) : {118} normal block at 0x00346300, 60 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
D:\Palmtime\Test\TestDoc.cpp(91) : {117} normal block at 0x00346288, 60 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
D:\Palmtime\Test\TestDoc.cpp(91) : {116} normal block at 0x00346210, 60 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
D:\Palmtime\Test\TestDoc.cpp(91) : {115} normal block at 0x00346198, 60 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
D:\Palmtime\Test\TestDoc.cpp(91) : {114} normal block at 0x00346120, 60 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
.....................省略偶知道是内存泄漏.该怎么解决这个问题呢?????请各位大大赐教!!!
{
char* sReturn[20];
for(int i=0;i<20;i++)
{
sReturn[i]=new char[60];
memset(sReturn[i],0,60);
}
int n=0;
while (TRUE)
{
TRACE("%d\r\n",n++);
Sleep(2000);
continue;
}
return 0L;
}上面的函数被启动为一个线程CreateThread(NULL,0,ProcDemo,this,0,&dwThreadID);
但程序关闭时,来个一堆这个东西
Detected memory leaks!
Dumping objects ->
D:\Palmtime\Test\TestDoc.cpp(91) : {120} normal block at 0x003463F0, 60 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
D:\Palmtime\Test\TestDoc.cpp(91) : {119} normal block at 0x00346378, 60 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
D:\Palmtime\Test\TestDoc.cpp(91) : {118} normal block at 0x00346300, 60 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
D:\Palmtime\Test\TestDoc.cpp(91) : {117} normal block at 0x00346288, 60 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
D:\Palmtime\Test\TestDoc.cpp(91) : {116} normal block at 0x00346210, 60 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
D:\Palmtime\Test\TestDoc.cpp(91) : {115} normal block at 0x00346198, 60 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
D:\Palmtime\Test\TestDoc.cpp(91) : {114} normal block at 0x00346120, 60 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
.....................省略偶知道是内存泄漏.该怎么解决这个问题呢?????请各位大大赐教!!!
用new 分配的内存干吗不用delete 释放啊
DWORD WINAPI ProcDemo(LPVOID lpParam)
{
char* sReturn[20];
for(int i=0;i<20;i++)
{
sReturn[i]=new char[60];
memset(sReturn[i],0,60);
}
int n=0;
while (TRUE)
{
TRACE("%d\r\n",n++);
Sleep(2000);
continue;
}
//////////////////////如果sRecturn其他地方要用,可以把下面的代码放到onclose()里。或退出调用的函数。
for(i=0;i<20;i++)
{
delete [] sReturn[i];
}
/////////////////////
return 0L;
}
{
delete [] sReturn[i];
sReturn[i] = NULL;
}
{
delete [] sReturn[i];
sReturn[i] = NULL;
}
{
delete [] sReturn[i];
sReturn[i] = NULL;
}
new [] / delete []
malloc/free
HeapAlloc,HeapFree
Entry()
{
main();
}main()
{
MessageBox(...);
}这样都有泄漏
你们怎么认为