How to force the GC in Java? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula gr√°tis
+ 2

How to force the GC in Java?

14th May 2019, 1:11 AM
Yurishama Yurishi
Yurishama Yurishi - avatar
3 Respostas
+ 6
You can't force it. It automatically operates behind the scenes.
14th May 2019, 1:13 AM
Sonic
Sonic - avatar
+ 6
Thanks Jay Matthews. I didn't know about System.gc();
14th May 2019, 1:21 AM
Sonic
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
Fermi - avatar