user3668129
user3668129

Reputation: 4820

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.

Upvotes: 6

Views: 523

Answers (1)

Elliott Frisch
Elliott Frisch

Reputation: 201447

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.

Upvotes: 8

Related Questions