Sunday, 29 April 2012

Reference Count

1. Reference Count keeps track of the number of blocks that point directly to the
    present block.
2. It is a technique of storing the number of references,pointer or handles to a
    resource such as an object,block of memory or disk space
3.Within each element in the heap,some extra space is provided for a reference
    counter.
4. The Reference counter contains the reference count indicating the number of
    pointers to that element that exist. 
5. When an element is initially allocated from the space list its reference count is
    set to 1.
6. Each time a new pointer to the element is created,its reference count is
    increased by 1.
7. Each time a  pointer is destroyed,the reference count is decreased by 1. 
8. When the reference count of an element reaches zero,the element is free
    and may be returned to the free space list. In other words, the element has
     become garbage that can be collected. 
9. Reference counts allow both garbage and dangling references to be avoided
    in most situations.

Note: Reference counts are best used when pointers between blocks never
          appear in cycle.

No comments:

Post a Comment