.NET Memory Management
-
Hi All, I have a doubt on the Out Of Memory Exception thrown by CLR!! Why does it do so, When Windows is providing a virtual memory of 4GB for a 32-bit processor for each and every process!! So according to this if an application starts, then a virtual memory of 4-GB is provided to it, and Windows keeps performing complex algorithms to swap data from RAM to physical memory!!! My doubt is when Windows is doing so much why at all we get an Out of Memory Exception?? I beleive that the memory management is a lot more complex than i have understood, can any of you please enlighten me on the same?? Thanks anyway, Rajesh
-
Hi All, I have a doubt on the Out Of Memory Exception thrown by CLR!! Why does it do so, When Windows is providing a virtual memory of 4GB for a 32-bit processor for each and every process!! So according to this if an application starts, then a virtual memory of 4-GB is provided to it, and Windows keeps performing complex algorithms to swap data from RAM to physical memory!!! My doubt is when Windows is doing so much why at all we get an Out of Memory Exception?? I beleive that the memory management is a lot more complex than i have understood, can any of you please enlighten me on the same?? Thanks anyway, Rajesh
OutOfMemoryExceptions can occur for other reasons, if I remember correctly. For example, GDI resources that don't get cleaned up properly will eventually run out. So, if you create an instance of a class that supports the
IDisposable
interface then remember toDispose()
it when you are done with it. ColinMackay.net "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius "If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell -
Hi All, I have a doubt on the Out Of Memory Exception thrown by CLR!! Why does it do so, When Windows is providing a virtual memory of 4GB for a 32-bit processor for each and every process!! So according to this if an application starts, then a virtual memory of 4-GB is provided to it, and Windows keeps performing complex algorithms to swap data from RAM to physical memory!!! My doubt is when Windows is doing so much why at all we get an Out of Memory Exception?? I beleive that the memory management is a lot more complex than i have understood, can any of you please enlighten me on the same?? Thanks anyway, Rajesh
Colin is correct. If you use any GDI or GDI+ objects, especially when doing you own custom drawing, and don't properly release them by calling Dispose when your done with them, the unmanaged underlying system handles don't get released and are eventually exhausted, causing your OutOfMemory Exception. There are other things that will cause this too, but not properly Disposing the objects you're using, no matter what they are, will result in exhausting one or more of the system handle pools. If you want a quick check of this, open TaskManager, click on its Processes tab, then go to the view menu and pick Select Columns. Turn on Handles, Threads, USER Objects, and GDI Objects. Click OK, then go to the list and file your app. Watch it run for a little while. If any of these counters just keeps rising the longer you use your app, this gives you a hint of where the problem lies. Handle counts usually don't rise above 1,000 in most cases. I have seen examples of piss-poor programming (in commercial software, no less!) where the Handle count grew above 100,000 handles in use! This is a REALLY BIG clue there's leaky code somewhere in that app... RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome