This articleneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged and removed. Find sources: "Unreachable memory" – news ·newspapers ·books ·scholar ·JSTOR(October 2015) (Learn how and when to remove this message) |
Incomputer programming,unreachable memory is ablock ofdynamically allocated memory where theprogram that allocated the memory no longer has any reachablepointer that refers to it. Similarly, anunreachable object is a dynamically allocatedobject that has no reachablereference to it. Informally, unreachable memory isdynamic memory that the program cannot reach directly, nor get to by starting at an object it can reach directly, and then following a chain of pointer references.
In dynamic memory allocation implementations that employ agarbage collector, objects are reclaimed after they become unreachable. The garbage collector is able to determine if an object is reachable; any object that is determined to no longer be reachable can bedeallocated. Manyprogramming languages (for example,Java,C#,D,Dylan,Julia) use automatic garbage collection.
In contrast, when memory becomes unreachable in dynamic memory allocation implementations that require explicit deallocation, the memory can no longer be explicitly deallocated. Unreachable memory in systems that use manual memory management results in amemory leak.
Some garbage collectors implementweak references. If an object is reachable only through either weak references or chains of references that include a weak reference, then the object is said to beweakly reachable. The garbage collector can treat a weakly reachableobject graph as unreachable and deallocate it. (Conversely, references that prevent an object from being garbage collected are calledstrong references; a weakly reachable object is unreachable by any chain consisting only of strong references.) Some garbage-collectedobject-oriented languages, such asJava andPython, feature weak references. TheJava packagejava.lang.ref
supports soft, weak and phantom references, resulting in the additional object reachability statessoftly reachable andphantom reachable.
Unreachable memory (in languages, like C, that do not reclaim) is often associated withsoftware aging.