[Mono-dev] Memory Leak (Bitmap)Image.FromStream(memory_stream)

rgclickit rglassmeyer at clickitinc.com
Thu Mar 23 20:51:30 UTC 2017


I believe I discovered a memory leak when creating Bitmaps from the
Image.FromStream call. The basic code to reproduce the problem is:

using (System.IO.MemoryStream ms = new System.IO.MemoryStream(_sourceArray))
{
     using (Bitmap srcBitmap = (Bitmap)Image.FromStream(ms)) {
     }
}

where _sourceArray is a byte[] for a bitmap image file. Call the above code
in a loop and memory will climb. When calling GC.WaitForPendingFinalizers(),
GC.Collect() memory still climbs but slower.

I have attached a solution, WinForms project that demonstrates this issue. 
BitmapTest.gz
<http://mono.1490590.n4.nabble.com/file/n4670327/BitmapTest.gz>  



--
View this message in context: http://mono.1490590.n4.nabble.com/Memory-Leak-Bitmap-Image-FromStream-memory-stream-tp4670327.html
Sent from the Mono - Dev mailing list archive at Nabble.com.


More information about the Mono-devel-list mailing list