Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is gc always invoked, even when heap space is continuously available at run-time?

According to the Java Platform, Standard Edition HotSpot Virtual Machine Garbage Collection Tuning Guide section titled "Generations"

When the young generation fills up, it causes a minor collection in which only the young generation is collected

and:

Eventually, the tenured generation will fill up and must be collected, resulting in a major collection, in which the entire heap is collected.

So if the application has finished the allocation phase, and throughout the execution of the application, the young and tenured generations are never filled (at all, at any stage), then gc will not occur even once?

If it will occur, what is the reason? Because such seems contrary to the linked documentation.

like image 622
user3668129 Avatar asked Dec 31 '15 20:12

user3668129


1 Answers

So if the application finished the allocation phase, and throughout the execution of the application, the young and tenured generations are not filled up (at all, in any stage), the gc will not occur even once ?

Yes. If the young and tenured generations are not filled (at any stage) then the gc may not occur (even once). It's up to the JVM runtime to manage memory, and that includes deciding when (or if) garbage collection occurs.

like image 90
Elliott Frisch Avatar answered Oct 25 '22 16:10

Elliott Frisch