Say I造就了比图。
Bitmap bitmap = new Bitmap(320, 200);
当我写给某几流时(就我的情况而言,正如HttpListenerResponse所介绍的那样,它带上了HttpResponseStream),所有东西都是罚款的:
bitmap.Save(stream, ImageFormat.Png);
我无需绘制蓝图。 处置法,轨道图所使用的资源将自动清理。 然而,直接写给一名Png到一个无法预见的溪流的问题是,这可能导致。 在GDI+发生一个通用错误,在我审判我的Ap app 时发生这种情况。 因此,我的法律现在如何看待:
using (MemoryStream ms = new MemoryStream())
{
bitmap.Save(ms, ImageFormat.Png);
ms.WriteTo(stream);
}
现在,除非我勾画。 之后,将予以披露。
Rephrased question to get more specific answers: Why does this leaking of Bitmap memory seem to depend on what type of stream I save it to?
Update: As I ve been asked in comments if I m sure it s a leak. Calling the above repeatedly in a stress test, my w3wp process will go up to gigs and gigs of memory used until my machine start swapping and it will not clean up.