lysergic-acid
lysergic-acid

Reputation: 20050

OutOfMemoryException even when app doesn't seem to consume max amount of memory

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?

Upvotes: 1

Views: 193

Answers (1)

Reed Copsey
Reed Copsey

Reputation: 564413

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.

Upvotes: 2

Related Questions