S
stevek
While researching a GDI+ bug I had Task Manager up to see what was happening
with my memory. I was very surprised to see that my application was
consuming a TON of memory and each time I repeated one specific task it
would grab another 9-10 Mb. I narrowed this down to a single method that
seems to be leaking memory but I don't see why it is. FYI, the process I'm
watching in TaskMgr is myapplication.vshost.exe
Here is the method that is eating up memory:
public static Image ImageFromBytes(byte[] data)
{
using (MemoryStream ms = new MemoryStream(data, 0, data.Length))
{
ms.Write(data, 0, data.Length);
return Image.FromStream(ms, true);
}
}
Simple, right? Well as soon as this method returns (which due to
IDisposable is closing and disposing my stream) the memory jumps up 9-10 Mb.
I don't get it, I don't see the problem. The size of the source byte[] is
around 120Kb and I would imagine the deserialized Image instance is about
the same.
I have also tested this outside of the debugger and am seeing the same
behavior.
Anyone have any ideas for me? Is there a bug in the above method??
-Steve
with my memory. I was very surprised to see that my application was
consuming a TON of memory and each time I repeated one specific task it
would grab another 9-10 Mb. I narrowed this down to a single method that
seems to be leaking memory but I don't see why it is. FYI, the process I'm
watching in TaskMgr is myapplication.vshost.exe
Here is the method that is eating up memory:
public static Image ImageFromBytes(byte[] data)
{
using (MemoryStream ms = new MemoryStream(data, 0, data.Length))
{
ms.Write(data, 0, data.Length);
return Image.FromStream(ms, true);
}
}
Simple, right? Well as soon as this method returns (which due to
IDisposable is closing and disposing my stream) the memory jumps up 9-10 Mb.
I don't get it, I don't see the problem. The size of the source byte[] is
around 120Kb and I would imagine the deserialized Image instance is about
the same.
I have also tested this outside of the debugger and am seeing the same
behavior.
Anyone have any ideas for me? Is there a bug in the above method??
-Steve