Skip to content

Explicit Garbage Collection Call

Description

Calling `gc` suggests to the JVM that the garbage collector should be run, and memory should be reclaimed. This is only a suggestion, and there is no guarantee that anything will happen. Relying on this behavior for correctness or memory management is an anti-pattern.

Examples

Insecure Code

java
System.gc();

Secure Code

java

Remediation

Remove explicit calls to `System.gc()` or `Runtime.getRuntime().gc()` and rely on the JVM's automatic garbage collection.

Rule Details

FieldValue
IDCODE-0263
CategoryGeneric
SeverityLOW
CWE
ConfidenceHIGH
ImpactLOW
LikelihoodHIGH
ExploitabilityCOMPLEX
Tagsbest-practice, audit
OWASPN/A

References