Geeks With Blogs


INauseous() Shawn Cicoria - Solution Architect, Craftsman and Artisan - INauseous() - Main Blog Here:

The CPU temperature monitor has been updated.

I was seeing GDI exceptions and tracked it down to just not releasing GDI handles.

So, dispose is not enough.  Need to call DestroyIcon to ensure that any unused icons are actually destroyed.  I had a Dispose() being called on the Icon object, but it wasn't enough.  So, I put a little "swap" out the old and then call DestroyIcon in the Icon Handle.  That seems to solve it.  The GDI objects in Task manager are now constant and run around 50 or so with small variations.

The following is the PInvoke signature.

[System.Runtime.InteropServices.DllImport( "User32.dll" )]
private static extern int DestroyIcon( System.IntPtr hIcon );

I attempted to leverage some Code Profilers (ANTS and SciTech); the first didn't help.  SciTech might have been able to but I just couldn't get it running on Vista with VS 2005 etc.  So, went down the old comment out and watch path to see which code path was causing the issues.

Posted on Thursday, November 30, 2006 4:25 PM | Back to top

Comments on this post: GDI+ Memory Leaks - When Dispose is not enough.

Comments are closed.
Comments have been closed on this topic.
Copyright © Shawn Cicoria | Powered by: