Is it possible to force garbage collection in Java, even if it is tricky to do? I know about System.gc();
and Runtime.gc();
but they only suggest t
On OracleJDK 10 with G1 GC, a single call to System.gc()
will cause GC to clean up the Old Collection. I am not sure if GC runs immediately. However, GC will not clean up the Young Collection even if System.gc()
is called many times in a loop. To get GC to clean up the Young Collection, you must allocate in a loop (e.g. new byte[1024]
) without calling System.gc()
. Calling System.gc()
for some reason prevents GC from cleaning up the Young Collection.