Dangling pointers and wild pointers in computer programming are pointers that do not point to a valid object of the appropriate type. These are special cases of memory safety violations.
Dangling pointers arise when an object is deleted or deallocated, without modifying the value of the pointer, so that the pointer still points to the memory location of the deallocated memory. As the system may reallocate the previously freed memory to another process, if the original program then dereferences the (now) dangling pointer, unpredictable behavior may result, as the memory may now contain completely different data. This is especially the case if the program writes data to memory pointed by a dangling pointer, a silent corruption of unrelated data may result, leading to subtle bugs that can be extremely difficult to find, or cause segmentation faults (*NIX) or general protection faults (Windows). If the overwritten data is bookkeeping data used by the system's memory allocator, the corruption can cause system instabilities.
Wild pointers arise when a pointer is used prior to initialization to some known state, which is possible in some programming languages. They show the same erratic behaviour as dangling pointers, though they are less likely to stay undetected.
Other articles related to "dangling pointer, pointer, dangling pointers, pointers":
... A pointer which refers to memory which has been deallocated is called a dangling pointer ... In languages with manual memory management, dangling pointers can arise when a programmer deallocates a pointers associated memory, then dereferences the pointer ... int *a = new int int *b = a delete b /* a and b are now dangling pointers */ *a = 4 /* Memory error we may be overwriting another pointer's data */ The simple existence ...
... To expose dangling pointer errors, one common programming technique is to set pointers to the null pointer or to an invalid address once the storage they point to has been released ... When the null pointer is dereferenced (in most languages) the program will immediately terminate—there is no potential for data corruption or unpredictable behavior ... This technique does not help when there are multiple copies of the pointer ...
Famous quotes containing the words pointer and/or dangling:
“The hardiest skeptic who has seen a horse broken, a pointer trained, or has visited a menagerie or the exhibition of the Industrious Fleas, will not deny the validity of education. A boy, says Plato, is the most vicious of all beasts; and in the same spirit the old English poet Gascoigne says, A boy is better unborn than untaught.”
—Ralph Waldo Emerson (18031882)
“And, indeed, is there not something holy about a great kitchen?... The scoured gleam of row upon row of metal vessels dangling from hooks or reposing on their shelves till needed with the air of so many chalices waiting for the celebration of the sacrament of food. And the range like an altar, yes, before which my mother bowed in perpetual homage, a fringe of sweat upon her upper lip and the fire glowing in her cheeks.”
—Angela Carter (19401992)