2

I am new to analyzing memory issues in Java. So pardon me if this question seems naive

I have application running with following JVM parameters set:

-Xms3072m -Xmx3072m 
-XX:MaxNewSize=1008m -XX:NewSize=1008m 
-XX:PermSize=224m -XX:MaxPermSize=224m -XX:SurvivorRatio=6 

I am using visualVM to monitor the usage : Here is what I see

enter image description here

The problem is, even when the application is not receiving any data for processing, the used memory doesn't go down. When the application is started, the used space starts low (around 1GB) but grows as the application is running. and then the used memory never goes down. My question is why the used heap memory doesn't go down even when no major processing happening in application and what configurations can be set to correct it. My understanding is if application is not doing any processing then the heap used should be less and heap memory available ( or max heap) should remain the same (3GB) in this case.

mehta
  • 735
  • 1
  • 11
  • 26
  • Do you mean the max heap size? – Sotirios Delimanolis Jun 07 '16 at 16:55
  • 1
    Why do you believe it should go down? – Peter Lawrey Jun 07 '16 at 17:02
  • See other answers/comment, but if you do have a memory leak, create a heap dump and analyze with eclipse MAT. http://www.eclipse.org/mat/ – OldProgrammer Jun 07 '16 at 17:31
  • Can you please clarify your question? Are you referring to the used heap? I think not since it clearly fluctuates. Do you mean the max heap size? Do you expect that memory to be released back to the OS? Is that what you're asking about? That was my assumption and I closed with a relevant duplicate. If that's not your question, please edit your question to clarify. – Sotirios Delimanolis Jun 07 '16 at 19:35
  • @SotiriosDelimanolis I have modified the question. – mehta Jun 08 '16 at 02:28

1 Answers1

6

This is a totally normal trend, even if you believe that it is not used there are probably threads running doing tasks that create objects that are unreferenced once the tasks are done, those objects are eligible for the next GC but as long as there is no minor/major GC they take more and more room in your heap so it goes up until a GC is triggered then you get the normal heap size and so on.

An abnormal trend will be the same thing but after a GC the heap size would be higher than the heap size just after the previous GC which is not the case here.

Your real question is more what my application is doing when is not receiving any data to process? For that a thread dump should help, you can launch jcmd to get the PID then launch jstack $pid to get the thread dump.

Here is an example of a typical trend in case of memory leak:

enter image description here

As you can see the starting heap size has changed between two GC, the new starting heap size is higher than the previous one which may be due to a memory leak.

Nicolas Filotto
  • 43,537
  • 11
  • 94
  • 122
  • 1
    Thanks for that reply. i will check thread dump. Another question though is, if GC is running why the heap size still not coming down. Or is that the major/minor GC is not running ? (I don't think this is possible because JVM would run GC). How can I verify this ? – mehta Jun 07 '16 at 17:38
  • Call Perform a GC from JVisual VM to trigger a major GC, the remaining heap size is the current memory foot print of your application composed of objects that are not unreferenced as they are still used by your application – Nicolas Filotto Jun 07 '16 at 17:49
  • Got it. In fact I just noticed that as soon as the used memory touch 3 GB (max size available), GC activity was performed and used memory came down to 1 GB. – mehta Jun 07 '16 at 18:42