Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does garbage collection work in java?

I knew that there are a lot of articles about java garbage collection but after searching I don't know exactly "when dose the garbage collection run in a java application?(when the application restart or while it still running)".

like image 426
gamo Avatar asked Mar 18 '23 21:03

gamo


1 Answers

Garbage Collector is a dameon thread. A dameon thread runs behind the application. It is started by JVM. The thread stops when all non-dameon threads stop.

The JVM controls the Garbage Collector; it decides when to run the Garbage Collector. JVM runs the Garbage Collector when it realizes that the memory is running low. The behavior of GC can be tuned by passing parameters to JVM.

One can request the Garbage Collection to happen from within the java program but there is no guarantee that this request will be taken care of by jvm.Check How to force garbage collection in Java?

Learn More ..

like image 80
Santhosh Avatar answered Mar 20 '23 11:03

Santhosh