- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I tested one of my big project with Intel and he said Inspector found some "GDI Resource Leak". I never understood why I said it was the resource leak. However the code seems to be correct. I use Microsoft Visual Studio 2005, but the 2008 does the same thing.
Here is how to reproduce the error for sure.
MyDlg.h
[cpp]// Class dialog class CMyDlg : public CDialog { ... private: HDC m_hdcBitmapTopAndBottomDC; }[/cpp]
MyDlg.cpp
[cpp]BOOL CMyDlg::OnInitDialog() { CDialog::OnInitDialog(); ... // Create DC HDC hDCMain = ::GetDC(m_hWnd); m_hdcBitmapTopAndBottomDC = CreateCompatibleDC(hDCMain); ::ReleaseDC(m_hWnd, hDCMain); ... } void CMyDlg::OnClose() { // Delete temporary DC DeleteDC(m_hdcBitmapTopAndBottomDC); m_hdcBitmapTopAndBottomDC = NULL; }[/cpp]
Here is the warning I got from Intel Inspector XE 2011.
ID Problem Sources Modules Object Size State
P11 GDI resource leak MyDlg.cpp Test.exe New
When exploring source of the warning, I got this line :
[cpp]m_hdcBitmapTopAndBottomDC = CreateCompatibleDC(hDCMain);[/cpp]
Even if DeleteDC is called correctly in the OnClose the dialog and OnClose and is indeed called.
I even tried in OnDestroy and the Destructor of the CMyDlg to be sure.
Is there something I don't understand ?
Best regards,
Martin
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Inspector XE 2011 can support "Detect resource Leaks" on Windows version only.
Are you using latest Update 4? Are you sure that DeleteDC() was called before doing regular works in Dlg::OnClose?
Can you post a workable test case so I can reproduce this problem on my side? Or you can submit a new issue with small test case to https://premier.intel.com(if contents are "private")
If you want to suppress all "Resource Leaks"from program in result, you can un-select "Detect resource leaks" item in "Configure Analysis Type" window.
Regards, Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm running Intel Inspector 2011 XE with Upgrade 4.
I'm sure that DeleteDC is calling because I did try on OnClose, before the OnDestroy and also in the Destructor of the dialog class. Also it's the same problem with calls "CreateCompatibleBitmap / DeleteObject"
I have attached to this response, an example (Microsoft Visual Studio 2005 MFC) that demonstrates the problem.
In the "Intel XE Results - r000mi1.inspxe", you will find the leakat IDP4.
Hope you will find the problem because I'm out of idea and I'm pretty sure there is no problem with this code.
Best regards,
Martin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for your test program.
I have to tell you that ReleaseDC() should be in Dlg::OnDestroy() since you use "OK" or "Cancel" button to exit, so OnClose() will not be executed (You can insert MessageBoxW() to verify execution path).
But the problem stillishere...I will report this to dev team, and temporarily useofdisabling "Detect resource leaks" I posted last time.
I will get backto you if any progress.
Regards, Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much Peter.
So I will wait your news with impatience. Since my goal was just to detect resource leak. And as our application is really huge, it would save us considerable time if it could works as expected.
Will you send me a private email or publish a notice on this thread when the problem will be fixed by Intel ?
Best regards,
Martin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for your anwser, sorry for the delay, the forum did not send me email about your response.... don't know why !
If I well undertand you mean that at higher level (2 or 3) Intel Inspector will not detect/analyse GDI leak ?
If the answer to this question is YES, than I don't understand why at level 1 the result are wrong, and for other higher level the problem is not analyse. So how can I scan forresouce (GDI) leak in my application ?
If the response to this question is NO, then I already try doing the two other preset memory leak (giving -mi2 [Detect Memory Problems]and -mi3 [Locate Memory Problems]in the command line). In those two cases, whenI do a leak voluntarily, it does not detect it ! So what's wrong ?
Best regards,
Martin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Martin,
The status of this issue has been changed, in latest Update 6. Memory check in all levels will report GDI resource leak.
I retested your attached project, that is true - memory check will report GDI resource leak, and Code Locations is at line with "m_hdc = CreateCompatibleDC(hDCMain);
If I use -
DeleteDC(m_hdc);
m_hdc = NULL;
in CIntelInspectorGDILeakDlg::OnDestroy(). There is no GDI resource leak detection again.
Regards, Peter

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page