Jump to content

Dangling reference

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Dhollander (talk | contribs) at 22:32, 13 March 2006. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

A dangling reference in a program is a reference to an object, record or variable which doesn't exist anymore.

In a programming language, a dangling reference occurs when a pointer to a local variable in a function is used after the function has terminated.

In relational database systems a dangling reference occurs when a foreign key refers to a record that doesn't exist anymore or was never created. It can be seen as the database equivalent of a dangling pointer.

Examples

A call to the C-program

int *f(int x) {
  return &x;
}

as in

main() {
  int a,b=2;
  a = *f(b);
}

returns a pointer to its argument, which ceased to exist. A dangling reference results.


Consider a database where a foreign key to employee #387 is given and no employee with id 387 exists, this is a situation of a dangling reference.

See also