liveBook · Manning

Reference counting

Reference counting is a memory-management technique that tracks references to an object or value and can reclaim it when its reference count reaches zero.

How 4 Manning books explain it

C++ Concurrency in Action, Second Edition

Reference counting is a memory-management technique that tracks how many references point to an object and reclaims it when the count reaches zero.

How it is used
Uses per-node access counts to address safe reclamation in concurrent data structures.
How deep it goes
Explains per-node counts through stack implementations and warns that shared_ptr operations are not guaranteed to be lock-free.
Examples
Compares stack implementations using shared_ptr, atomic_shared_ptr, and split reference counts.
What you can do after
Apply reference counting to stack-node reclamation using shared pointers or split counts.

Read how C++ Concurrency in Action, Second Edition explains reference counting →

Python How-To

Reference counting is an automatic memory-management technique that tracks how many references identify each object and releases an object when its count reaches zero.

How it is used
Explains how Python automatically releases objects that no longer have references.
How deep it goes
Defines increments, decrements, and destruction with code, but defers cyclic-reference handling to gc.
Examples
Uses Task instances, reassignment, dictionary and list references, sys.getrefcount, del, and an overridden __del__ method.
What you can do after
Diagnose/debug with it by observing reference-count changes and object destruction in custom class instances.

Read how Python How-To explains reference counting →

Code Like a Pro in Rust

Reference counting is a memory-management technique that tracks the number of references to an object and reclaims it when that count reaches zero.

How it is used
Enables shared ownership when Box cannot serve multiple pointers to the same data.
How deep it goes
Explains count changes and zero-count release, but leaves custom pointer implementation as an unsafe-pointer exercise.
Examples
Shows a doubly linked list using `Rc<RefCell<ListItem<T>>>` for item references and `Box<T>` for data.
What you can do after
Apply it via Rc for single-threaded sharing or Arc for sharing across threads.

Read how Code Like a Pro in Rust explains reference counting →

Python Concurrency with asyncio

A memory-management technique that tracks the number of active references to each object and reclaims an object when that count reaches zero.

How it is used
Explains why CPython uses the global interpreter lock and why threads cannot safely modify shared reference counts concurrently.
How deep it goes
Defines incrementing, decrementing, reclamation, and a lost-update race, without detailing broader garbage-collection internals.
Examples
Uses integers, dictionaries, lists, and a two-thread reference-count increment race to make the mechanism concrete.
What you can do after
Evaluate how reference-count updates contribute to CPython's thread-safety constraints and the global interpreter lock.

Read how Python Concurrency with asyncio explains reference counting →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.