0

I've been trying for hours to figure this out. When this executes it will run until system runs out of memory. I tried disposing the bmp's created after used, it made no difference. I also tried disposing the webbrowser but then I need to run the webpage on a loop with the right height/width etc to take a capture of it. I tried creating a new webbrowser everything it loops then dispose but it then wouldn't work. Can anyone see what may be happening here?

The loop:

        wbcondor1.AllowNavigation = true;
        wbcondor1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wbcondor1_DocumentCompleted);
        wbcondor1.Navigate("blanked out");

the document completed

  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();
    }

Thanks all, hopefully someone can see what I'm missing :(

eddie
  • 1,252
  • 3
  • 15
  • 20
mxadam
  • 169
  • 2
  • 14
  • Comment out each part of your logic until the leak disappears. For example, comment out the body of `wbcondor1_DocumentCompleted()` -- do you still run out of memory eventually? – cdhowie Oct 02 '12 at 18:40
  • didnt even think of doing that. Just did it and it will still run out, just keeps building with every loop – mxadam Oct 02 '12 at 18:47
  • Then this block is not the source of your problem. Run your code in a profiler and look for huge allocations, or a huge number of small allocations, then try to track down where they are coming from. – cdhowie Oct 02 '12 at 18:49
  • well the code is really simple now, its just a webbrowser and the command to goto x website every x seconds :s – mxadam Oct 02 '12 at 18:50
  • Then perhaps the browser history is growing too large. Use the profiler, Luke. – cdhowie Oct 02 '12 at 18:52

2 Answers2

0

If an Exception is thrown,

condor1bmp.Dispose();

will not be called.

Always use a using statement to wrap things that implement IDisposable.

Other than that, there are plenty of things that can cause an OutOfMemoryException when working with a Bitmap, other than actually running out of memory.

For several possibilities, see

C# Out of Memory when Creating Bitmap

Is it possible that your stress test is hitting one of those conditions?

Community
  • 1
  • 1
Eric J.
  • 147,927
  • 63
  • 340
  • 553
  • i just commented out the document completed part and it still rises which means everytime i tell the webbrowser to refresh the page the memory builds each time – mxadam Oct 02 '12 at 18:50
0

Just to let people know who run into this error. Ran out of memory on line x. It is a problem with internet explorer itself. It can be stopped by turning of active scripting in IE settings to disable javascript.

mxadam
  • 169
  • 2
  • 14