Garbage collection has more profound impact on the application in contrary to what most engineers think. In order to optimize memory and garbage collection settings and to troubleshoot memory-related problems, one has to analyze Garbage Collection logs.
Enabling GC logs
GC Logging can be enabled by passing below-mentioned system properties during application startup
Until Java 8:
Below is the system property that is supported by all version of Java until JDK 8.
From Java 9:
Below is the system property that is supported by all version of Java starting from JDK 9.