I am currently running a small java class for scientific calculations on graphs (which internally creates lots of huge collections) from within Eclipse on MacOSX Snow Leopard. I have a Macbook with 2GB of RAM and to successfully run the app without OutOfMemory Error I need to run it from eclipse with -Xmx1200m (I know this is very much).
It takes about 500seconds to do all the computations I need to run and it also uses up all the memory I have given it (I monitored it with macosx progress monitor and it goes to 1,2GB for Real Mem)
After this application is done my MacOSX is almost unusable. Even if I close Eclipse everything becomes sluggish and slow. I also notice that whatever I do afterwards (even after closing Eclipse) that e.g. Finder navigation is very slow. It takes ages to render some folders or to change directories. Sometimes I restart the system to be able to work again efficiently.
I would like to understand what is happening in the background when this happens?
I was under the impression, that when a java class / app has finished running, that the Garbage Collector at least at the end will cleanup everything and I would have expected that other programs are free to use this memory again. But it “feels” like a memory leak which affects the whole system, even if the Java app is not running anymore.
I would appreciate any hints or readings in this direction.
What you’re experiencing is called page-swapping. The OS has evicted (or paged-out) a bunch of virtual memory pages to disk in order to accommodate the requirements of your Java code. When your program is done, and you try to switch back to some other program you have running, the OS has to page-in from disk before it can resume.
You can see all of this happening by using tools such as top or Activity Monitor.