views:

201

answers:

4

Does anyone know why I would get an OutOfMemoryException when TaskMgr.exe says my process is only taking up ~1GB of memory?

+3  A: 

There probably isn't enough contiguous free memory to do what you want.

See here.

SLaks
Good point. What are you doing in code?
Hamish Grubijan
A: 

Could it be that the IDE limits the amount of memory you can use? In which case, you can give run parameters to expand the amount of memory available. At least, that's how it is in eclipse.

piggles
+1  A: 

If you have no swap space defined, increasing the Virual Memory size may help.

Also, realize that, when you're using .NET, the process memory limits on 32bit .NET code tend to be much lower than the theoretical limits. It's very common to start receiving out of memory errors somewhere between 1.2GB and 1.6GB of memory usage - well below the theoretical 2GB limit. (This is true even if allocating small chunks of memory.)

Moving to a 64bit platform would most likely eliminate this issue. (It's possible that your 1GB is not entirely accurate, either - TaskMgr does a very poor job of estimating memory allocation.)

Reed Copsey
Its actually **more** likely to happen at a lower threshold if you are allocating small objects, but still large enough to be on the LOH. Especially when the lifetime of the objects can vary significantly. Fragmentation in the GC can cause lots of headaches.
GrayWizardx
Well, I consider any object big enough to be allocated on the LARGE object heap to not be a small object ;) But yes, any LOH allocations tend to fragment your system, and the more you have the worse it gets. This can happen, though, even with small objects that are under the LOH size thresholds.
Reed Copsey
+1  A: 

If you want a better tool than Taskmanager download The SysInternals Suite from MS and use the Process Explorer Utility to monitor your app while its running. Select View->Select Columns->Process Memory and set the columns you want to monitor. It gives you a much better read on whats happening in memory.

That being said my bet is lack of contiguous memory available in your Heap is the problem.

kloucks