OutOfMemory is intermittent, maybe here's why
After a call to Graphics.DrawImage, an OutOfMemory error might occur. The
probability of an error has some correlation with the size of the image but
is not reliable. Even with an image of a few hundred megabytes, sometimes
the error occurs and sometimes not. Some random postings on the web and
newsgroups say the image file is broken, well, the image file doesn't
alternate between being broken and not. The error is intermittent.
When running under a debugger, sometimes Visual Studio asserts that the
error occured in some other random place such as Application.Run. But not
always. So I think sometimes the stack is getting smashed.
Now get this. Inserting some calls to GC.Collect *increases* the
probability of an OutOfMemory error. Deleting those calls *decreases* the
probability. This seems backwards, right? Well, not if the errors are due
to one particular kind of bug.
I think Graphics.DrawImage is forgetting to pin a pointer before calling a
Win32 API. I think the garbage collector is collecting stuff that the Win32
API thought it was going to use.
Date:Thu, 23 Aug 2007 15:02:42 +0900
Author:
|