Skip to content
Commitwise
Menu

Garbage collection

Also called: GC

The runtime periodically finds objects nothing can reach any more and frees them for you.

Definition

The JVM and Android runtime use a garbage collector (GC). Instead of counting references, it starts from live roots (threads, static fields) and frees everything it can't reach, so reference cycles are not a problem. The cost is that collection happens at times you don't control, which can cause short pauses.

In practice

A Spring service creates thousands of short-lived DTOs per request; the GC cleans them up in the young generation without you writing any cleanup code.

Learn it in context

Lessons that use this term.

Related terms

Esc

Type to search the whole site.