Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this indicative of a memory leak in Java?

Tags:

java

memory

Does the following graph indicate that I am using memory and it is not being garbage collected?

enter image description here

I expected the orange graph (the allocated heap) to go down once I start using less of the heap.

  • Is this an invalid assumption?
  • Once allocated, does the heap not shrink until the program closes?
like image 518
sdasdadas Avatar asked Feb 04 '13 22:02

sdasdadas


People also ask

Will this situation cause a memory leak in Java?

In Java, the memory leak is a situation when the garbage collector does not recognize the unused objects and they remain in the memory indefinitely that reduces the amount of memory allocated to the application. Because the unused objects still being referenced that may lead to OutOfMemoryError.

How do you check if there are memory leaks?

One way to check for memory leak is to press and hold down your Windows key and tap the Pause/Break key to bring up System Properties. Click on the Performance tab and check System Resources for the percentage of free or available RAM.


1 Answers

It is clear from the graph that your JVM is capable of shrinking the heap. This can be seen from the orange line taking a slight dip just before 3:10pm.

However, later on the JVM chooses to not shrink the heap. This is almost certainly because an insufficiently large fraction of the heap is unused. The behaviour is controlled by -XX:MinHeapFreeRatio and -XX:MaxHeapFreeRatio.

For a discussion, see http://stopcoding.wordpress.com/2010/04/12/more-on-the-incredible-shrinking-jvm-heap/

like image 60
NPE Avatar answered Sep 28 '22 07:09

NPE