Splitting hairs
Tracing
Main article: Tracing garbage collection
Tracing garbage collection is the most common type of garbage collection, so much so that “garbage collection” often refers to tracing garbage collection, rather than other methods such as reference counting.
Reference counting
Main article: Reference counting
Reference counting garbage collection is where each object has a count of the number of references to it. Garbage is identified by having a reference count of zero. An object’s reference count is incremented when a reference to it is created and decremented when a reference is destroyed. When the count reaches zero, the object’s memory is reclaimed.[15]