我發誓我知道這個答案,但我忘了。加載大量的圖像導致內存不足
我有這個功能。它加載位圖並繪製它們。它可以快速連續調用。大約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