Skip to content
Latchkey

What Is a Lifetime in Reference Types?

A lifetime describes the region of a program over which a reference remains valid, anchored to how long the referenced data lives. The compiler uses lifetimes to verify that no reference can be used after its target has been freed. In some languages they are inferred, and in others written explicitly to relate the lifetimes of several references.

Why it matters

Reasoning about lifetimes is how the compiler statically rules out dangling references. Understanding them is key to satisfying a borrow checker and designing safe reference-passing APIs.

Related guides

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