An OutOfMemory error indicates that the application cannot allocate enough memory to execute properly. This situation normally occurs when there are too many unused objects that have accumulated and that have not been de-allocated by the garbage collector. For a multi-threaded application, threads that have finished their execution cycle might still be holding on to the memory and might not have been destroyed by the garbage collector.
To detect the cause of OutOfMemory errors
Insert a break point at the line where the Runtime Exception occurs.
Run the application.
When the application hits the break point, click the View menu and select Memory Statistics. The window that appears shows the memory statistics of the application at the break point. These statistics indicate where the application may be using most of the allocated memory.
If it is suspected that the application may be running out of memory because the garbage collector may not have de-allocated some objects, click on the View menu and select Objects.
In the window that appears, click Refresh to view the list of objects that are alive at the break point in the application. If some of the objects in the list should be de-allocated, set them to Null in the code. The garbage collector will realize that these objects are no longer referenced and will de-allocate them.
Select Threads from the View menu if it is suspected that some threads may be holding on to the memory even after they have been de-allocated.
Click the links below to see images of the tools described in this article: