Zeddy2
September 28th, 2005, 06:52 AM
Hi guys...
Code is:
void SetIcon()
{
HICON hFolderIcon = (HICON)::LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ICON_FOLDER), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR );
GetDlgItem(IDC_BUTTON_OMGWTFLOL)->SendMessage(BM_SETIMAGE, IMAGE_ICON, (LPARAM)hFolderIcon);
}
Yes that is MFC related but this is win32 question. Note scope of LoadImage().
Now I originally believe that cause hFolderIcon is created on stack, then handle is used to set icon on button, windows deletes GDI object when button is destroyed. Even though hFolderIcon goes out of scope & gets destoryed in code, icon is still on button, so I always believe that windows deletes GDI object and no gdi resource leak happen.
Now today I do this code and run through Devpartner instrumentation. If you not know what this is, it like Boundschecker on drugs. Part of Devpartner detect memory and resource leak in code. So if you code this:
void func()
{
char* blah = new char[MAX_PATH];
}
This obvious a mem leak - Devpartner instrumentating finds it and reports it after runtime. Devpartner do this for everything - COM object, handles etc.
Now when I run above code (HICON code) through devpartner, it says I have memleak for GDI object even though it gone out of scope.
So devpartner believes win32 does not destroy gdi handle when button is destroyed = mem leak. I believe win32 does destroy gdi handle = no mem leak.
I not refer to gdi object cleanup/ garbage collection, i refer to explcit handling of object, if that make sense.
Which is right? :)
Code is:
void SetIcon()
{
HICON hFolderIcon = (HICON)::LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ICON_FOLDER), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR );
GetDlgItem(IDC_BUTTON_OMGWTFLOL)->SendMessage(BM_SETIMAGE, IMAGE_ICON, (LPARAM)hFolderIcon);
}
Yes that is MFC related but this is win32 question. Note scope of LoadImage().
Now I originally believe that cause hFolderIcon is created on stack, then handle is used to set icon on button, windows deletes GDI object when button is destroyed. Even though hFolderIcon goes out of scope & gets destoryed in code, icon is still on button, so I always believe that windows deletes GDI object and no gdi resource leak happen.
Now today I do this code and run through Devpartner instrumentation. If you not know what this is, it like Boundschecker on drugs. Part of Devpartner detect memory and resource leak in code. So if you code this:
void func()
{
char* blah = new char[MAX_PATH];
}
This obvious a mem leak - Devpartner instrumentating finds it and reports it after runtime. Devpartner do this for everything - COM object, handles etc.
Now when I run above code (HICON code) through devpartner, it says I have memleak for GDI object even though it gone out of scope.
So devpartner believes win32 does not destroy gdi handle when button is destroyed = mem leak. I believe win32 does destroy gdi handle = no mem leak.
I not refer to gdi object cleanup/ garbage collection, i refer to explcit handling of object, if that make sense.
Which is right? :)