Dipanshu Verma
Dipanshu Verma

Reputation: 499

java:Why is full GC called when -Xms and -Xmx are unequal?

I was reading a doc on java GC

A memory space, either Old or Permanent, is full and to accommodate new objects or classes, it needs to be expanded towards its max size, if the relevant parameters have different values. In other words, if ‐Xms and ‐Xmx have different values and if the size of Old needs be increased from ‐Xms towards ‐Xmx to accommodate more objects, a FullGC is called. Similarly, if ‐XX:PermSize and ‐XX:MaxPermSize have different values and the Permanent Space needs to be increased towards ‐XX:MaxPermSize to accommodate new java classes, a FullGC is called. This can be avoided by always setting ‐Xms and ‐Xmx as well as ‐XX:PermSize and ‐XX:MaxPermSize to the same value.

Wondering why is a FullGC called in this case? Whats the use?

Upvotes: 3

Views: 2369

Answers (2)

Amit Bhati
Amit Bhati

Reputation: 5659

  • -Xms and -Xmx does not determine the amount of memory your application needs.
  • If -Xms value is different then -Xmx, full GC is called in order to resize the heap to fulfill your memory requirement of your application.
  • If the above parameters are same, the resizing will be avoided altogether, because your application launches with a heap which is big enough for it. In short, you are saying to JVM, my application will never need heap bigger than this.

Upvotes: 0

Peter Lawrey
Peter Lawrey

Reputation: 533820

Resizing the heap is not just a matter of adding more memory. There is data structures the GC uses which have to be resized and this requires a FullGC to be preformed to do this.

Upvotes: 2

Related Questions