In
computer programming
Computer programming or coding is the composition of sequences of instructions, called computer program, programs, that computers can follow to perform tasks. It involves designing and implementing algorithms, step-by-step specifications of proc ...
, unreachable memory is a
block
Block or blocked may refer to:
Arts, entertainment and media Broadcasting
* Block programming, the result of a programming strategy in broadcasting
* W242BX, a radio station licensed to Greenville, South Carolina, United States known as ''96.3 ...
of
dynamically allocated memory where the
program that allocated the memory no longer has any reachable
pointer that refers to it. Similarly, an unreachable object is a dynamically allocated
object
Object may refer to:
General meanings
* Object (philosophy), a thing, being, or concept
** Object (abstract), an object which does not exist at any particular time or place
** Physical object, an identifiable collection of matter
* Goal, an a ...
that has no reachable
reference
A reference is a relationship between objects in which one object designates, or acts as a means by which to connect to or link to, another object. The first object in this relation is said to ''refer to'' the second object. It is called a ''nam ...
to it. Informally, unreachable memory is
dynamic 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 a
garbage 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 be
deallocated. Many
programming language
A programming language is a system of notation for writing computer programs.
Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
s (for example,
Java
Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
,
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 a
memory leak
In computer science, a memory leak is a type of resource leak that occurs when a computer program incorrectly manages memory allocations in a way that memory which is no longer needed is not released. A memory leak may also happen when an objec ...
.
Some garbage collectors implement
weak 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 be . The garbage collector can treat a weakly reachable
object graph as unreachable and deallocate it. (Conversely, references that prevent an object from being garbage collected are called ''strong references''; a weakly reachable object is unreachable by any chain consisting only of strong references.) Some garbage-collected
object-oriented
Object-oriented programming (OOP) is a programming paradigm based on the concept of '' objects''. Objects can contain data (called fields, attributes or properties) and have actions they can perform (called procedures or methods and impleme ...
languages, such as
Java
Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
and
Python, feature weak references. The
Java package
A Java package organizes Java classes into namespaces,
providing a unique namespace for each type it contains.
Classes in the same package can access each other's package-private and protected members.
In general, a package can contain the fo ...
java.lang.ref
supports soft, weak and phantom references, resulting in the additional object reachability states softly reachable and phantom reachable.
Unreachable memory (in languages, like C, that do not reclaim) is often associated with
software aging
In software engineering, software aging is the tendency for software to Software failure, fail or cause a system failure after running continuously for a certain time, or because of ongoing changes in systems surrounding the software. Software a ...
.
External links
*
{{Memory management navbox
Automatic memory management