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
What Is a Borrow Checker?A borrow checker is a compile-time analysis that enforces rules about references so a program cannot use memo…
What Is Ownership in Memory Management?Ownership is a model where each resource has a single owning variable responsible for freeing it, making clea…
What Is Reference Counting?Reference counting tracks how many references point to an object and frees it automatically when that count d…