首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

线程里申请内存,关闭程序时内存泄露,该怎么处理

2012-03-05 
线程里申请内存,关闭程序时内存泄露我在线程里用new申请内存空间,关闭程序时内存泄露.ThethreadWin32Threa

线程里申请内存,关闭程序时内存泄露
我在线程里用new申请内存空间,关闭程序时内存泄露.
The   thread   'Win32   Thread '   (0x508)   has   exited   with   code   0   (0x0).
The   thread   'Win32   Thread '   (0xd68)   has   exited   with   code   0   (0x0).
The   thread   'Win32   Thread '   (0x9a0)   has   exited   with   code   0   (0x0).
Detected   memory   leaks!
Dumping   objects   ->
thrdcore.cpp(311)   :   {1198}   client   block   at   0x01410F98,   subtype   c0,   68   bytes   long.
a   CWinThread   object   at   $01410F98,   68   bytes   long
thrdcore.cpp(311)   :   {1192}   client   block   at   0x01410C50,   subtype   c0,   68   bytes   long.
a   CWinThread   object   at   $01410C50,   68   bytes   long
d:\initio_project\07_0712_fwconfig_v306\fwconfig\fwconfigdlg.cpp(721)   :   {1186}   normal   block   at   0x01650040,   41943040   bytes   long.
  Data:   <5129682674873844>   35   31   32   39   36   38   32   36   37   34   38   37   33   38   34   34  
thrdcore.cpp(311)   :   {1185}   client   block   at   0x01410908,   subtype   c0,   68   bytes   long.
a   CWinThread   object   at   $01410908,   68   bytes   long
thrdcore.cpp(311)   :   {1179}   client   block   at   0x00388F18,   subtype   c0,   68   bytes   long.
a   CWinThread   object   at   $00388F18,   68   bytes   long
Object   dump   complete.
The   program   '[3580]   FWConfig.exe:   Native '   has   exited   with   code   0   (0x0).

[解决办法]
没有在所有的出口都delete[] pRandom
[解决办法]
关闭进程的时候,所有内存都会强制归还,没啥泄露不泄露的了。
关键是看你这个“泄露”量是不是稳定的。
[解决办法]
ouyh12345(五岭散人) 说得有道理
不过不知道pGetBuffer会不会成为野指针(int *pGetBuffer = pRandom;)最好是加一句
pGetBuffer = NULL;
[解决办法]
CFWConfigDlg *Config_dlg = (CFWConfigDlg*)lParam;
--------
外部有释放吗?没有的话,delete Config_dlg;

...

if (!(Config_dlg -> HardDiskStream( m_Sector_Number)))
goto _error;
if (!(Config_dlg -> InverseStream( m_Sector_Number)))
goto _error;
Sleep(200);
}

_error:
delete[] pRandom;
delete Config_dlg; // 如果其他地方没有释放
...

热点排行