1

I am trying to improve the performance of my web-application so I decided to do profiling of it.
When doing this I noticed that after completion of a long process when I start task manager I saw that java.exe is taking too much memory.

By the way I've checked it after 2-3 hours after the process complete and cpu is in stable state.
I saw in the profiler's VM elementry view, Used memory is 5 GB and free memory is 15 GB and in task manager total memory used by java.exe is 41 GB.
What is this free memory?
Is it something like now this much memory will be taken by java?
I noticed as the process begins and running used memory as well as free memory grows, but after completion used memory decreased but not free memory.
I am wondering is there any problem with my application or it is normal?

NIVESH SENGAR
  • 1,285
  • 5
  • 19
  • 43

3 Answers3

3

Profilers usually show the Heap memory usage. So, 5 GB of your heap is probably being used, and 15 GB is available. Task manager shows the total memory used by the process, which includes heap memory and non-heap memory such as the 'Perm Gen' memory in Sun JVM. Following post has a good collection of resources to understand this in detail.

Java Memory explained (SUN JVM)

Community
  • 1
  • 1
Samarth Bhargava
  • 4,196
  • 3
  • 17
  • 16
2

Are you sure this is GB and not MB? I'm not trying to imply anything, but that is a huge amount of ram for a system you haven't profiled yet. And I would love to know what type of application this is that is written in Java and consumes that much ram. We have these large ram servers at work but we run EMR systems for a hospital system with 1,000's of users at a time (running Java...).

If infact it is GB, you have a huge codebase or store a lot of objects in ram. Possibly a lot of objects still allocated that cannot be consumed by the GC.

If I understand your tool correctly, it is explaining that Java is reserving system ram but has not allocated it to objects. This would be your free ram. Used memory is that consumed by the codebase and objects in memory. Java will sometimes hold ram that is not currently being used and not release it to the OS to ensure continuity of memory addresses (prevents fragmenting ram). Mike

Michael Rice
  • 1,173
  • 5
  • 13
1

When you start a server JVM, it sets the maximum heap size to 1/4 of the memory by default, but I suspect you have set your maximum heap size to 40 GB.

The JVM reserves this much virtual memory on startup, but the memory is not allocated by the OS to the application until it uses it.

This means you can set the maximum to 80 GB and it will appear to be using 80 GB of virtual immediately (even for a hello world program) The actual memory used can be far less.

In your case, the heap size has grown to 20 GB (touched by the application) of which you are using 5 GB and 15 GB isn't being used. If you used more memory, the heap size could grow to 40 GB total.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • So it will not release this memory even after completion of the process when this much memory is not needed? – NIVESH SENGAR Mar 09 '12 at 09:05
  • When the JVM exists all the memory is released. The un-used memory can be swapped to disk and the main memory reused, but this is usually a bad idea performance wise. What is your Full GC times like if you are using up to 20 GB? BTW: the Azul JVM is the only JVM I know of which returns memory to the OS. – Peter Lawrey Mar 09 '12 at 09:11
  • Full GC time is approx 14 minutes. Does it matter? – NIVESH SENGAR Mar 09 '12 at 09:15
  • 1
    That's impressive. ;) It doesn't have to matter depending on the application. I am more used to systems which go to great lengths to avoid GCs even if they take milli-seconds. I was just curious. – Peter Lawrey Mar 09 '12 at 09:29