javagarbage-collectionjava-12

What is the difference between GC.run and GC.run_finalization?


Could someone explain me (best would be to lead to documentation) what is the difference between the two:

jcmd ${jpid} GC.run_finalization
jcmd ${jpid} GC.run

As in the application (springboot + tomcat) after a test (using gatling) much memory stays allocated and not freed. "Saw" graph shows that GC is feeing something but not everything In the application life cycle:

The only documentation I found is https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#gc-- , but it confused me even more (I understood that GC.run_finalization would suggest finalization of objects for release while GC.run would suggest memory objects to be prepared for future reuse and not necessary freed).

Thanks in advance


Solution

  • (best would be to lead to documentation)

    There is documentation for jcmd and its subcommands here:

    That documentation explains that jcmd <pid or class> help will list the available commands, and jcmd <pid or class> help <command> will give you the help information for <command>.


    What is the difference between GC.run and GC.run_finalization?

    From what I can make out from a brief look at the JVM source code:


    (I understood that GC.run_finalization would suggest finalization of objects for release while GC.run would suggest memory objects to be prepared for future reuse and not necessary freed).

    It is not like that. A normal GC cycle is something like this:

    The finalized object are left where they are. They will be deleted by the GC in a future collection provided that they are still unreachable.

    Note that finalization is an old mechanism for tidying up objects before they are deleted. The vast majority of Java objects are never finalized.


    So this is the explanation for the behavior that you are seeing.