Sunday, 29 April 2012

Dangling References


1. Dangling Reference refers to a pointer variable whose value points to something
    which is no longer meaningful.
2. It is an access path that continues to exist after the lifetime of the associated data
    object.An Access path ordinarily leads to the location of a data object.
3. A dangling occurs when there is a reference to storage that has been deallocated
    or may have also been reallocated for another purpose.
4. At the end of the lifetime of the object,this block of storage is recovered for
     reallocation at some later point to another data object.
5. However,the recovery of the storage block does'nt necessarily destroy the
    existing accsess paths to the block and thus they may continue to exist as
    dangling references.
6. Dangling references are a particular serious problem for storage management
    because they may compromise  the integrity of the entire run-time structure
    during program execution.
7. For Example: An assignment to a non existent data object via a dangling
    reference can modify storage already allocated to another data object of an
    entirely different type.
8.                            main()
                             {
                                 int *p;
                                 p=dangle();
                             }
                             int * dangle()
                             {
                               int i=23;
                               return &i;
                             }
 Procedure dangle in the C Program returns a pointer to the storage bound to the
 local name i. The Pointer is created by the operator and applied to i. when control
 returns to main from dangle,thestorage for locals is freed & can be used for other
 purposes.Since p in main refers to this storage,the use of p is a dangling reference.

No comments:

Post a Comment