Skip to content
Latchkey

What Is Reference Counting?

Reference counting is a memory-management technique that keeps a count of how many references point to each object, incrementing on new references and decrementing when they go away. When the count reaches zero the object is freed immediately. It reclaims memory promptly but cannot collect cycles of objects that reference each other.

Why it matters

Reference counting gives deterministic cleanup without a separate collection pass, which suits resources that must be released promptly. Its blind spot is reference cycles, which is why weak references exist to break them.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →