referencecounting
Reference counting is a form of memory management in which each object keeps a tally of how many references point to it. When a reference to an object is created, the count is incremented; when a reference is destroyed or reassigned, the count is decremented. If the count reaches zero, the object is deallocated.
Implementations typically maintain a per-object reference counter that is updated during pointer assignments and scope exits.
Reference counting is widely used through smart pointers and language runtimes. Examples include C++ shared_ptr, Rust
Advantages include deterministic destruction and low pause times, making it suitable for real-time or resource-constrained environments
Cycles pose a major challenge: two or more objects referencing each other can keep counts above zero.
Reference counting contrasts with tracing garbage collection, which identifies unreachable objects via program-wide reachability analysis. In