How to force the GC in Java? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 2

How to force the GC in Java?

14th May 2019, 1:11 AM
Yurishama Yurishi
Yurishama Yurishi - avatar
3 Réponses
+ 6
You can't force it. It automatically operates behind the scenes.
14th May 2019, 1:13 AM
Sonic - avatar
+ 6
Thanks Jay Matthews. I didn't know about System.gc();
14th May 2019, 1:21 AM
Sonic - avatar
+ 5
Sonic's original answer isn't entirely wrong. System.gc() doesn't *force* garbage collection to occur - It prompts the JVM to do GC but does not guarantee it.
14th May 2019, 1:42 AM
Fermi - avatar