我发誓我知道这个答案,但我忘了。加载大量的图像导致内存不足
我有这个功能。它加载位图并绘制它们。它可以快速连续调用。大约300左右的位图后,应用程序崩溃,出现System.OutOfMemoryException。
请告诉我,我错了又来了:)
private void PaintPicture()
{
string FullPath = Global.RunttimePath + EditType.FilePath;
if (File.Exists(FullPath))
{
Image i = Image.FromFile(FullPath);
//DrawImage(i, pnlPicture, pbColor.BackColor); //I disabled this so the problem is not here
i.Dispose();
//GC.Collect(); //I know I know... I should never call GC. So disabled it :)
}
else
{
//DrawImage(Properties.Resources.Fail800, pnlPicture, Color.White, true);
}
}
在你的示例代码中,你没有做错任何事情,要么你的问题的来源是其他地方,这段代码只是“St原料打破了骆驼回来“或问题是在你删除的代码发布你的问题在这里。 – 2014-11-06 18:26:18
图像是GDI资源,无论如何都不需要GC'd。 – TaW 2014-11-06 18:38:57