Re: Memory Leak (Bitmap)Image.FromStream(memory_stream)

Robert Jordan <[email protected]>
Newsgroups gmane.comp.gnome.mono.devel
Message-ID <[email protected]>
On 24.03.2017 20:17, Robert Jordan wrote:
> On 23.03.2017 21:51, rgclickit wrote:
>> 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)) {
>>      }
>> }
>>
>
> I cannot reproduce this. The odds are that you're not computing
> the memory usage correctly.
>
> See
> http://www.mono-project.com/docs/advanced/performance-tips/#understanding-memory-usage


I was testing with a too large bitmap and hence too few iterations/sec.
With a 1x1 bitmap the leak started to become evident, so it
probably depends on how often Image.FromStream is getting called.

The code behind Image.FromStream is pretty complex because the
underlying unmanaged library (libgdiplus) knows nothing about
managed streams.

Hard to say, where to leak is. It might be an unmanaged one...

You may want to file a bug, ideally with a test case which doesn't
depend on WinForms, like this one:

---
using System;
using System.Drawing;
using System.IO;

class Program
{
	static void Run ()
	{
		using (var stream = File.OpenRead ("test.bmp"))
			using (Image.FromStream (stream)) {
                 }
	}

         static void Main ()
         {
                 for (int i = 0; i < 100000; i++)
                         Run ();
         }
}
---

Robert


_______________________________________________
Mono-devel-list mailing list
[email protected]
http://lists.dot.net/mailman/listinfo/mono-devel-list
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.