Reputation: 27073
The OutOfMemoryException
for my applications is thrown way before the system itself runs out of memory, as explained by:
MSDN Blogs - Out of memory? Easy ways to increase the memory available to your program.
When you run your C# application, you might get an
OutOfMemoryException
thrown, even if your machine has lots of memory. [...] That 4 Gigs is divided into half: the user application gets the lower half and the OS gets the upper. (This boundary can be changed: see below).
By request, I need to visualize how much memory is available for my application and the current usage. Current usage can be retrieved using Process.GetCurrentProcess();
and others, but how to determine the memory available to my application at run-time? I just cannot figure out.
Upvotes: 5
Views: 2432
Reputation: 27515
You can use MemoryFailPoint to check before a large allocation. This isn't exactly what you're asking for, but if your failure is at a particular known large allocation point, this at least allows you to cleanly handle the allocation failure at the point that it occurs.
Upvotes: 2