It’s Kind of Spontaneous. First, we cannot force garbage collection to run (System.gc()). Sometimes it will but it’s unpredictable. In Java, garbage collection runs automatically in the background, managed by the Java Virtual Machine (JVM). The exact timing of its execution isn’t deterministic and depends on various factors, including: Heap Memory Usage: Garbage collection typically occurs when the JVM detects that the heap memory is running low and needs to free up space. JVM Implementation: Different JVM implementations (like HotSpot, OpenJ9, etc.) have their own algorithms and heuristics for deciding when to run the garbage collector. Garbage Collection Algorithm: The