我一直在嘗試幾個小時來弄清楚這一點。當它執行時,它會運行直到系統內存不足。 我嘗試過使用後創建的bmp,它沒有任何區別。 我也試過配置網頁瀏覽器,但後來我需要在正確的高度/寬度等的循環上運行網頁來拍攝它。 我試圖創建一個新的webbrowser它的所有循環然後處置,但它不會工作。 任何人都可以看到這裏可能發生了什麼?C#內存不足錯誤
循環:
wbcondor1.AllowNavigation = true;
wbcondor1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wbcondor1_DocumentCompleted);
wbcondor1.Navigate("blanked out");
文檔完成
private void wbcondor1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
Bitmap condor1bmp = new Bitmap(600, 1000);
wbcondor1.DrawToBitmap(condor1bmp, new Rectangle(wbcondor1.Location.X, wbcondor1.Location.Y, wbcondor1.Width, wbcondor1.Height));
if (Convert.ToString(condor1bmp.GetPixel(553, 558)) == "Color [A=255, R=232, G=30, B=48]") { c1to1.Text = "lower"; }
if (Convert.ToString(condor1bmp.GetPixel(553, 584)) == "Color [A=255, R=232, G=30, B=48]") { c1to2.Text = "lower"; }
if (Convert.ToString(condor1bmp.GetPixel(553, 608)) == "Color [A=255, R=232, G=30, B=48]") { c1to3.Text = "lower"; }
if (Convert.ToString(condor1bmp.GetPixel(553, 633)) == "Color [A=255, R=232, G=30, B=48]") { c1to4.Text = "lower"; }
if (Convert.ToString(condor1bmp.GetPixel(553, 658)) == "Color [A=255, R=232, G=30, B=48]") { c1to5.Text = "lower"; }
if (Convert.ToString(condor1bmp.GetPixel(553, 558)) == "Color [A=255, R=0, G=175, B=88]") { c1to1.Text = "higher"; }
if (Convert.ToString(condor1bmp.GetPixel(553, 584)) == "Color [A=255, R=0, G=175, B=88]") { c1to2.Text = "higher"; }
if (Convert.ToString(condor1bmp.GetPixel(553, 608)) == "Color [A=255, R=0, G=175, B=88]") { c1to3.Text = "higher"; }
if (Convert.ToString(condor1bmp.GetPixel(553, 633)) == "Color [A=255, R=0, G=175, B=88]") { c1to4.Text = "higher"; }
if (Convert.ToString(condor1bmp.GetPixel(553, 658)) == "Color [A=255, R=0, G=175, B=88]") { c1to5.Text = "higher"; }
// bmp.Save("condor1.gif");
condor1bmp.Dispose();
}
感謝所有,希望有人能看到我錯過了什麼:(
註釋掉邏輯的每個部分,直到泄漏消失。例如,註釋掉'wbcondor1_DocumentCompleted()'的主體 - 最終是否還會耗盡內存? – cdhowie
甚至沒有想到這樣做。只是做了它,它仍然用完,只是不斷建設與每個循環 – mxadam
然後這個塊不是你的問題的來源。在分析器中運行你的代碼,並尋找巨大的分配,或大量的小分配,然後嘗試追蹤它們來自哪裏。 – cdhowie