EDIT: I reformulated it to be a question and moved the answer to the answers part...
In a relatively complex multithreaded .NET
application I experienced OutOfMemoryException
even in the cases I could think there is no reason for it.
The situation:
- The application is 32bit.
- The application creates lot of (thousands) short lived objects that are considered small (less than approx. 85kB).
- Additionaly it creates some (hundreds) short lived objects that are considered large (greater than approx. 85kb). This implies these objects are allocated at LOH (large object heap).
- Both classes for these objects define finalizer (
~MyFinalizer(){...}
).
The symptoms:
OutOfMemoryException
- Looking at the app via memory profiler, there are thousands of the small objects eligible for collection, but not collected and thus block large amount of memory.
The questions:
- Why the app exhausts entire heap?
- Why there is lot of "dead" objects still present in the memory?