Groups | Blog | Home
all groups > dotnet drawing api > august 2007 >

dotnet drawing api : OutOfMemory is intermittent, maybe here's why


Norman Diamond
8/23/2007 12:00:00 AM
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.
Michael C
8/28/2007 12:00:00 AM
[quoted text, click to view]

It's possible memory is getting fragmented and while there is a lot of free
memory there isn't a free contiguous block of memory. I'm not sure how to
solve it though, I would have thought the GC.Collect would fix it. Maybe
GC.Collect doesn't wait for the complete collection to occur.

Michael

Norman Diamond
8/30/2007 12:00:00 AM
[quoted text, click to view]

Now I've observed that the commit charge of the program runs to 1.3GB on a
machine that has only 1GB of RAM. The program didn't crash yet in Vista,
but does in XP (in fact its crashes in XP are becoming pretty reliable
instead of intermittent).

So obviously physical memory is fragmented but I think that shouldn't
matter. Does the .Net Framework fragment its virtual memory differently
under Vista than it does under XP?

I'm not sure what difference it makes if GC.Collect might not be waiting for
collection to complete. I still think it looks like the stack is getting
smashed because the collector does move something when the rest of the
runtime isn't ready for it to be moved.
AddThis Social Bookmark Button