内存泄漏win32(除了新的免费删除malloc之外) [英] memory leaks win32(other than new delete malloc free)

查看:114
本文介绍了内存泄漏win32(除了新的免费删除malloc之外)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我从未对任何操作使用新的delete malloc calloc.
我只使用过一次new运算符即可在winmain()&中创建xyz类的对象.退出项目时释放该对象.

我在应用程序中使用了vmr,vfw,gdi gdi plus,icon而不是普通按钮

播放每个新视频后,内存增加(在任务管理器中)
甚至当我移动鼠标或单击鼠标左键时,mem也会增加

我应该如何查找是否有内存泄漏.

当光标移动到任意两个图标(HOME& EXIT)时,以下代码用于文本显示

In my project i never used new delete malloc calloc for any operation.
i used new operator only once to create object of xyz class in winmain() & free that object while exiting the project.

i had use vmr, vfw, gdi gdi plus ,icon instead of normal button in my application

after playing each new video memory is increases( in task manager)
even some times when i move mouse or click left button mem increases

how should i find is there any memory leak.

below code is used to textual display when cursor is move to any two icon(HOME & EXIT)

case WM_MOUSEMOVE:
{
HWND hwButton_home=GetDlgItem(g_hDialogWindow,IDC_ICON_HOME);
HWND hwButton_exit=GetDlgItem(g_hDialogWindow,IDC_ICON_EXIT);

WINDOWPLACEMENT lpwndpl_home;
WINDOWPLACEMENT lpwndpl_exit;

GetWindowPlacement(hwButton_home,&lpwndpl_home);
GetWindowPlacement(hwButton_analyze,&lpwndpl_exit);


		
if( ((lpwndpl_home.rcNormalPosition.left)<LOWORD(lParam)&& LOWORD(lParam)<(lpwndpl_home.rcNormalPosition.right)) && ((lpwndpl_home.rcNormalPosition.top)<HIWORD(lParam)&& HIWORD(lParam)<(lpwndpl_home.rcNormalPosition.bottom)))
{
if(IsWindowEnabled(hwButton_home))
{
 ::SetWindowPos(GetDlgItem(g_hDialogWindow, IDC_MODE_TEXT), HWND_NOTOPMOST,  lpwndpl_home.rcNormalPosition.left,  lpwndpl_home.rcNormalPosition.bottom, 45,18, SWP_NOZORDER);      
  SetWindowText(GetDlgItem(g_hDialogWindow, IDC_MODE_TEXT), "HOME");
   ShowWindow(GetDlgItem(g_hDialogWindow, IDC_MODE_TEXT), TRUE);

}
}

else if( ((lpwndpl_exit.rcNormalPosition.left)<LOWORD(lParam)&& LOWORD(lParam)<(lpwndpl_exit.rcNormalPosition.right)) && ((lpwndpl_exit.rcNormalPosition.top)<HIWORD(lParam)&& HIWORD(lParam)<(lpwndpl_exit.rcNormalPosition.bottom)))
{	
if(IsWindowEnabled(hwButton_exit))
 {
::SetWindowPos(GetDlgItem(g_hDialogWindow, IDC_MODE_TEXT), HWND_NOTOPMOST,  lpwndpl_exit.rcNormalPosition.left+5,  lpwndpl_exit.rcNormalPosition.bottom, 75,18, SWP_NOZORDER);      
   SetWindowText(GetDlgItem(g_hDialogWindow, IDC_MODE_TEXT), "EXIT");
 ShowWindow(GetDlgItem(g_hDialogWindow, IDC_MODE_TEXT), TRUE);

}
  }

else
                
ShowWindow(GetDlgItem(g_hDialogWindow, IDC_MODE_TEXT), FALSE);
}
break;


当我将鼠标放在该图标上时,meme会增加4个字节.


when i placed mouse on this icon 4 bytes of meme increases.

推荐答案

您正在调用的API函数也可能会分配内存.销毁对象后,将释放该内存.如前所述,当操作期间使用的内存增加时,您不能确定内存泄漏.仅当应用程序终止时有未释放的内存时,您才有内存泄漏.

使用调试版本,您可以在CWinApp派生类的ExitInstance()中调用AfxCheckMemory()来检查堆.但这不会检测到所有泄漏.
The API functions you are calling may also allocate memory. This memory is freed when the objects are destroyed. As already noted, you can''t be sure that there are memory leaks when the used memory increases during operation. Only when there is unfreed memory upon application termination, you have memory leaks.

With debug builds, you may call AfxCheckMemory() within ExitInstance() of your CWinApp derived class to check the heap. But this will not detect all leaks.


如上所述.任务管理器无法可靠地向您显示内存泄漏.由于任务管理器中的数量正在增加,请尝试执行此操作-这将有助于查看是否确实存在泄漏.

运行您的应用程序,并在值增加时查看任务管理器.接下来,将您的应用程序最小化到任务栏.如果任务管理器中的内存恢复为正常"状态,则可能没有泄漏.

最小化应用程序会导致OS释放工作集内存.当您的应用程序使用内存时,该额外的内存将放入工作集"中,并且在不需要时不会立即释放-该内存将保留,以备您再次需要时使用.如果操作系统中的其他组件需要,它将被释放.最小化会使操作系统释放该内存.

希望有帮助.
As stated. Task Manager doesn''t reliably show you memory leaks. Since the number in task manager is increasing, try this - it will help see if there really is a leak.

Run your application and look at the task manager as the values increase. Next, minimize your application to the task bar. If the memory in the task manager drops back to what appears "normal", you probably don''t have any leaks.

Minimizing the application causes the OS to release the working set memory. As your app uses memory, that addtional memory is put in a "working set" and not immediately released when it isn''t needed - it''s held in case you need it again. It would be released if needed by something else in the OS. Minimizing causes the OS to release that memory.

Hope that helps.


任务管理器中内存的增加不是内存泄漏的直接证据.
如果您确定这是程序的问题,则某些工具可能会有所帮助,例如boundsChecker
memory increasing in task manager is not directly evidence of memory leaking.
if you make sure it is your program''s issue, some tools may help e.g. boundsChecker


这篇关于内存泄漏win32(除了新的免费删除malloc之外)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆