Reference Counting - Use in Garbage Collection

Use in Garbage Collection

As a garbage collection algorithm, reference counting tracks, for each object, a count of the number of references to it held by other objects. If an object's reference count reaches zero, the object has become inaccessible, and can be destroyed.

When an object is destroyed, any objects referenced by that object also have their reference counts decreased. Because of this, removing a single reference can potentially lead to a large number of objects being freed. A common modification allows reference counting to be made incremental: instead of destroying an object as soon as its reference count becomes zero, it is added to a list of unreferenced objects, and periodically (or as needed) one or more items from this list are destroyed.

Simple reference counts require frequent updates. Whenever a reference is destroyed or overwritten, the reference count of the object it references is decremented, and whenever one is created or copied, the reference count of the object it references is incremented.

Reference counting is also used in disk operating systems and distributed systems, where full non-incremental tracing garbage collection is too time consuming because of the size of the object graph and slow access speed.

Read more about this topic:  Reference Counting

Famous quotes containing the words garbage and/or collection:

    But could a dream send up through onion fumes
    Its white and violet, fight with fried potatoes
    And yesterday’s garbage ripening in the hall,
    Flutter, or sing an aria down these rooms
    Even if we were willing to let it in,
    Gwendolyn Brooks (b. 1917)

    Bolkenstein, a Minister, was speaking on the Dutch programme from London, and he said that they ought to make a collection of diaries and letters after the war. Of course, they all made a rush at my diary immediately. Just imagine how interesting it would be if I were to publish a romance of the “Secret Annexe.” The title alone would be enough to make people think it was a detective story.
    Anne Frank (1929–1945)