Javatpoint Logo
Javatpoint Logo

Java System gc() Method

The gc() method of System class runs the garbage collector. Through this method, JVM makes best effort to reuse the memory of discarded objects for quick reuse.

Syntax

Example 1

Test it Now

Output:

before garbage collection = 100
after garbage collection = 0

Example 2

Test it Now

Output:

null
Next TopicJava System



Help Others, Please Share

facebook twitter pinterest