class Icon_ResouceLeak { static void Main(string[] args) { // the program starts with 18 GDI objects.. var bmp = new Bitmap("imagePath"); // 25 GDI objects.. IntPtr ptr = bmp.GetHicon(); // 30 GDI Objects.. Icon newIcon = Icon.FromHandle(ptr); var clonedIcon = (Icon)newIcon.Clone(); // 33 GDI objects.. DestroyIcon(newIcon.Handle); // 30 GDI objects .. clonedIcon.Dispose(); // 27 GDI objects .. newIcon.Dispose(); // 27 GDI objects.. bmp.Dispose(); // still 27 GDI objects? } [DllImport("user32.dll", CharSet = CharSet.Auto)] extern static bool DestroyIcon(IntPtr handle); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)