Q:

Analysis on Memory Management

I'm doing Memory management analysis for my Java web application,
Before starting my tomcat the free memory was around 595 MB, Once I started the server the free memory goes to 151 MB. When I took the Heap dump, the objects were occupying 262 MB. 
So will tomcat alone take remaining 181 MB?
Another question is, I ran Load Test with 500 Users. The free memory goes to 8MB, When I took heap dump here, It was around 265MB. So free space 151 MB is reduced to 8MB, What could be reason

A:

Firstly, read and understand http://www.linuxatemyram.com/ for why "free" memory numbers are much lower than you might think.
Secondly, Java allocates its entire heap upfront from the operating system, although it doesn't touch or dirty the pages until they're actually used. This gives you top output like:
 PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND         
9521 pjc       17   0 1288m 524m  25m S  0.0 13.3  58:31.92 java

That's me running Eclipse; the VIRT column shows that Java probably has a 1024Mb maximum heap size; on top of that are libraries and memory allocated for storing the compiled Java. However only 524Mb of that is currently in RAM.
Your heap dump is the best guide to how much memory your application is using - provided that's after it's done a garbage collection.

