Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Dangling pointer
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{short description|Pointer that does not point to a valid object}} [[File:Dangling Pointer.svg|thumb|Dangling pointer]] '''Dangling pointers''' and '''wild pointers''' in [[computer programming]] are [[data pointer|pointers]] that do not point to a valid object of the appropriate type. These are special cases of [[memory safety]] violations. More generally, '''dangling references''' and '''wild references''' are [[Reference (computer science)|references]] that do not resolve to a valid destination. Dangling pointers arise during [[object destruction]], when an object that is pointed to by a given pointer is deleted or deallocated, without modifying the value of that said pointer, so that the pointer still points to the memory location of the deallocated memory. The system may reallocate the previously freed memory, and if the program then [[dereference operator|dereferences]] the (now) dangling pointer, ''[[undefined behavior|unpredictable behavior]] may result'', as the memory may now contain completely different data. If the program writes to memory referenced by a dangling pointer, a silent corruption of unrelated data may result, leading to subtle [[software bug|bugs]] that can be extremely difficult to find. If the memory has been reallocated to another process, then attempting to dereference the dangling pointer can cause [[segmentation fault]]s (UNIX, Linux) or [[general protection fault]]s (Windows). If the program has sufficient privileges to allow it to overwrite the bookkeeping data used by the kernel's memory allocator, the corruption can cause system instabilities. In [[object-oriented language]]s with [[Garbage collection (computer science)|garbage collection]], dangling references are prevented by only destroying objects that are unreachable, meaning they do not have any incoming pointers; this is ensured either by tracing or [[reference counting]]. However, a [[finalizer]] may create new references to an object, requiring [[object resurrection]] to prevent a dangling reference. Wild pointers, also called uninitialized 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 behavior as dangling pointers, though they are less likely to stay undetected because many compilers will raise a warning at compile time if declared variables are accessed before being initialized.<ref>{{Cite web|url=https://gcc.gnu.org/onlinedocs/gcc-4.0.2/gcc/Warning-Options.html|title = Warning Options - Using the GNU Compiler Collection (GCC)}}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)