tags:

views:

27

answers:

3

When will a program get an 'Out of memory exception'. Is it when not having enough virtual address range or because of not having enough physical memory?

As per my understanding, it should happen only when not enough virtual address is available as physical storage can be made available by paging un-used sections.

Please clarify.

Thanks, Suresh.

A: 

When you run out of addressable space for the program to access. This normally means virtual address range, but if you have enough RAM, it would be the physical memory.

Oded
+1  A: 

Total memory available = physical (RAM) plus page file(s).

When both are full, you get the exception on any further memory allocation requests.

On some systems this is qualified further by the fact that the kernel reserves a portion of physical RAM for itself, so user mode programs are left to compete for the rest.

Steve Townsend
Steve - not entirely correct. If this is a 32bit OS, the amount of addressable space may be less than actual installed RAM. If the process reaches the limit of addressable space, the exception will occur.
Oded
+1  A: 

If you're seeing an OutOfMemoryException, this is presumably a .Net application. Ironically, the conditions you describe are pretty much never the source of an OutOfMemoryException in .Net.

In most cases, it's better to think of an OutOfMemoryException as being an OutOfSomeCriticalResourceButNotRAMIronicallyEnoughException. Or even worse: as one example, .Net throws an OutOfMemoryException when you attempt to open an invalid image file.

MusiGenesis