This project is read-only.

Memory leak in using ColorKeyBitmap

Oct 13, 2011 at 4:51 PM

I have called bellow code many times, memory usage rapidly increased!


BitmapSource bitSrc = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(...);

ColorKeyBitmap colorKeyBmp = new ColorKeyBitmap();
colorKeyBmp.TransparentColor = Color.FromArgb(255, 255, 255, 255);
colorKeyBmp.Source = bitSrc;

img.Source = colorKeyBmp;


But change code below, no memory leak!


img.Source = bitSrc;


Please help me!



Oct 13, 2011 at 8:34 PM

I have just checked in a workaround. I implemented IDisposable on CustomBitmap and ChainedBitmap, and use private reflection to break the problematic cycle. I also added a GC button to the UI to help test.

Oct 14, 2011 at 3:04 AM

Thank you very much for your help!