1

I am developing a .NET based application (.NET 4) that crashes after running for some time on a System.OutOfMemoryException

When examining the app's process in Task Manager or attempted to use other tools such as CLR Profiler and ANTS Memory Profiler, it doesn't seem like the application is maxing out on available RAM or any other limit that may be (I believe Windows has a limit per process as well as .NET itself probably is limited in some way).

Here's a screenshot from the ANTS Profiler from the time shortly before the crash.

Total amount of unamanged memory (in case it's not clearly seen in the image is ~ 285 MB, and total size of objects in all heaps is ~76MB)

I also checked the "Handles" count in taskmgr, looks to be around ~8120 handles for the app's process at the time of crash.

Profiler stats image How can I further examine what is going on? What possible causes can cause such an exception?

4
  • What are you trying to allocate when you hit this error? Is it a very large object? Commented Aug 7, 2013 at 16:04
  • It's an image (Bitmap). It is not "very large" in size (around 50kb). Can this be some underlying native exception in disguise? (like something coming from GDI) Commented Aug 7, 2013 at 16:06
  • 1
    It's very likely not a memory issue, then :( Commented Aug 7, 2013 at 16:15
  • Net has a 1 GB per object limit and in 64 bit can get 4 gb. But according to your report the tolal is less than 1 GB. Please post the line of code that is crashing and the loop if it is in a loop. Commented Aug 7, 2013 at 16:31

1 Answer 1

2

It's an image (Bitmap). It is not "very large" in size (around 50kb). Can this be some underlying native exception in disguise? (like something coming from GDI)

Yes, that is likely the cause. GDI often throws OutOfMemoryExceptions when there is an error that has nothing related to memory consumption.

I would suggest checking the Bitmap you are trying to load, and verifying that it's correctly formatted in a format supported by GDI.

This is a long term bug on Connect, with an offical response of:

you're seeing one of the idosyncracies of the drawing engine (GDI+) here. GDI+ likes to return OutOfMemoryExceptions in cases that have nothing to do with memory. Unfortunately GDI+ is a component that we get from Windows so we cannot address these issues

...

We often see these when you pass invalid parameters to a function...

Checking the call which loads the Bitmap, as well as the format specifics of the image file may lead you to the "real" underlying cause.

Sign up to request clarification or add additional context in comments.

10 Comments

I believe the same image is being loaded many times, until a certain point where it just fails. This suggests that there's nothing wrong with the actual image format... Can i somehow get some extra error details from GDI+ that will assist in what's happening?
@lysergic-acid Unfortunately, not that I know of. Is the image file locked somehow, or being written at all, etc?
@lysergic-acid Are you disposing of the images when you're done? If you run out of handles, GDI will fail, and you'll get this error... Check the handle counts with Task Manager before it throws - if you're near 10000 (the default limit), then you've got a resource/handle leak somewhere...
The images unfortunately are behind held in memory for the lifetime of the process (this is the current design, and a pretty bad one at it).
@lysergic-acid I suspect you're running out of handles. You need to clean up after yourself, and dispose the images when you're done with them.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.