Reference counting
lastmod 2022-10-04created 2022-10-041 edits
Reference counting is one way of managing memory and a form of garbage collection. Its structure is simple. A dynamic unit (an object) holds a reference count; when the object is referenced (the reference is copied), the count is incremented, and when the reference is no longer used, the count is decremented. Usually, once the count reaches 0, the object is no longer considered valid and is removed from memory.
With this method, whether an object is valid or invalid is determined definitively at the point of use, and it is fast because it only increments and decrements a count. It can also be implemented easily in programming languages that do not perform dynamic garbage collection.