Memory Management Glossary: G
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z
garbage : Garbage consists of objects that are dead.
In [tracing garbage collection](/u/f992775ea91d0285#term-tracing-garbage-collection), the term is sometimes
used to mean objects that are known to be dead; that is,
objects that are [unreachable](/u/ced5e8494ccaae80#term-unreachable).garbage collection : Also known as
*GC*.
Garbage collection (GC), also known as *automatic memory
management*, is the automatic [recycling](/u/611c5a77bde93a2f#term-recycle) of
[dynamically allocated](/u/5696710a733ccf6f#term-heap-allocation) [memory
(2)](/u/367f5f45f9800ccb#term-memory-2). Garbage collection is performed by a [garbage
collector](#term-garbage-collector) which recycles memory that it can prove will never
be used again. Systems and languages which use garbage
collection can be described as *garbage-collected*.
Garbage collection is a tried and tested memory management
technique that has been in use since its invention in the
1950s. It avoids the need for the programmer to
[deallocate](/u/b18026a6b8cfa4c8#term-free-1) memory [blocks](/u/4c6aaf4e0e0b7eb6#term-block)
explicitly, thus avoiding a number of problems: [memory
leaks](/u/367f5f45f9800ccb#term-memory-leak), [double frees](/u/433f84a577790d37#term-double-free), and [premature frees](/u/5195e3271b5de55e#term-premature-free). The
burden on the programmer is reduced by not having to
investigate such problems, thereby increasing productivity.
Garbage collection can also dramatically simplify programs,
chiefly by allowing modules to present cleaner interfaces to
each other: the management of object storage between modules
is unnecessary.
It is not possible, in general, for a [garbage
collector](#term-garbage-collector) to determine exactly which [objects](/u/f63e411ec871b42a#term-object) are
still [live](/u/34ad814de80e6063#term-live). Even if it didn’t depend on future input,
there can be no general algorithm to prove that an object is
live (cf. the Halting Problem). All garbage collectors use
some efficient approximation to liveness. In [tracing
garbage collection](/u/f992775ea91d0285#term-tracing-garbage-collection), the approximation is that an object can’t
be live unless it is [reachable](/u/611c5a77bde93a2f#term-reachable). In [reference
counting](/u/611c5a77bde93a2f#term-reference-counting), the approximation is that an object can’t be live
unless it is [referenced](/u/611c5a77bde93a2f#term-reference). Hybrid algorithms are also
possible. Often the term *garbage collection* is used narrowly
to mean only tracing garbage collection.
There is a large body of published work on particular and
general garbage collection algorithms.
Historical note
Garbage collection was first invented by John McCarthy in
1958 as part of the implementation of [Lisp](/u/884599c4278a5039#term-lisp).
Other significant languages offering garbage collection
include [Java](/u/884599c4278a5039#term-java), [ML](/u/884599c4278a5039#term-ml), [Modula-3](/u/884599c4278a5039#term-modula-3),
[Perl](/u/884599c4278a5039#term-perl), [Prolog](/u/884599c4278a5039#term-prolog), and [Smalltalk](/u/884599c4278a5039#term-smalltalk). Major
applications using garbage collection include Emacs and
AutoCAD; usually, you can’t tell whether an application does
or not, but these have extension languages that expose the
fact.
Similar term
[automatic memory management](/u/9b03e2fad7c35ce0#term-automatic-memory-management).
Opposite term
[manual memory management](/u/367f5f45f9800ccb#term-manual-memory-management).
See also
[conservative garbage collection](/u/b107b7d39b75ccb0#term-conservative-garbage-collection), [copying garbage collection](/u/b107b7d39b75ccb0#term-copying-garbage-collection), [distributed garbage collection](/u/433f84a577790d37#term-distributed-garbage-collection), [generational garbage collection](#term-generational-garbage-collection), [incremental garbage collection](/u/7010622dc3b8d8f9#term-incremental-garbage-collection), [parallel garbage collection](/u/5195e3271b5de55e#term-parallel-garbage-collection).
Related publication
[McCarthy (1960)](/u/80406cde1a6844cf#mccarthy60).garbage collector : Also known as
*collector*.
A (garbage) collector is (an implementation of) a
[garbage collection](#term-garbage-collection) algorithm.
This term is often used when referring to particular
implementations or algorithms, for example, “the
Boehm–Demers–Weiser *collector*”.GB : See
[gigabyte](#term-gigabyte).GC : See
[garbage collection](#term-garbage-collection).General Protection Fault : Also known as
*GPF*.
A General Protection Fault on the Windows platforms is the
equivalent of a [segmentation violation](/u/699ff3e2d070663d#term-segmentation-violation) on Unix.generation : A generation is a set of objects of similar age.
A [generational garbage collector](#term-generational-garbage-collection) will typically divide the set of all objects into
generations, and [condemn](/u/b107b7d39b75ccb0#term-condemned-set) all the
objects in a generation together. Rather than allowing whole
generations to age, the [collector (1)](/u/b107b7d39b75ccb0#term-collector-1) can
[promote](/u/5195e3271b5de55e#term-promotion) objects into older generations as
they survive successive [collection cycles](/u/b107b7d39b75ccb0#term-collection-cycle).
New objects are usually allocated in the youngest or
[nursery generation](/u/79d1d3e473607e01#term-nursery-generation), but if we know that particular
objects will be long-lived, we might want to allocate them
directly in an older generation. Thus, more loosely, a
generation is a set of objects which have similar expected
[lifetimes](/u/34ad814de80e6063#term-lifetime).
See also
[bucket](/u/4c6aaf4e0e0b7eb6#term-bucket).
In the MPS
The [client program](/u/b107b7d39b75ccb0#term-client-program) specifies the generational
structure of a [pool](/u/5195e3271b5de55e#term-pool) (or group of pools) using a
[generation chain](#term-generation-chain). See [Garbage collection](https://www.ravenbrook.com/project/mps/master/manual/html/topic/collection.html#topic-collection).A data structure that specifies the structure of the
[generations](#term-generation) in a [pool](/u/5195e3271b5de55e#term-pool) (or group of pools).
See [Garbage collection](https://www.ravenbrook.com/project/mps/master/manual/html/topic/collection.html#topic-collection).generation scavenging : See
[generational garbage collection](#term-generational-garbage-collection).generational garbage collection : Also known as
*generation scavenging*.
Generational garbage collection is [tracing garbage
collection](/u/f992775ea91d0285#term-tracing-garbage-collection) that makes use of the [generational
hypothesis](#term-generational-hypothesis). [Objects](/u/f63e411ec871b42a#term-object) are gathered together in
[generations](#term-generation). New objects are allocated in
the *youngest* or *nursery* generation, and [promoted](/u/5195e3271b5de55e#term-promotion) to *older* generations if they survive. Objects
in older generations are [condemned](/u/b107b7d39b75ccb0#term-condemned-set)
less frequently, saving CPU time.
It is typically rare for an object to refer to a younger
object. Hence, objects in one generation typically have few
[references](/u/611c5a77bde93a2f#term-reference) to objects in younger
generations. This means that the [scanning](/u/699ff3e2d070663d#term-scan) of
old generations in the course of collecting younger
generations can be done more efficiently by means of
[remembered sets](/u/611c5a77bde93a2f#term-remembered-set).
In some purely functional languages (that is, without update),
all references are backwards in time, in which case remembered
sets are unnecessary.
See also
[remembered set](/u/611c5a77bde93a2f#term-remembered-set).
In the MPS
The [AMC (Automatic Mostly-Copying)](https://www.ravenbrook.com/project/mps/master/manual/html/pool/amc.html#pool-amc) and [AMCZ (Automatic Mostly-Copying Zero-rank)](https://www.ravenbrook.com/project/mps/master/manual/html/pool/amcz.html#pool-amcz) pool classes
support generational garbage collection.generational hypothesis : Also known as
*infant mortality*.
*Infant mortality* or *the generational hypothesis* is the
observation that, in most cases, young [objects](/u/f63e411ec871b42a#term-object) are
much more likely to [die](/u/433f84a577790d37#term-dead) than old objects.
Strictly, the hypothesis is that the probability of death as a
function of age falls faster than exponential decay (inverse
hyper-exponential), but this strict condition is not always
required for techniques such as [generational garbage
collection](#term-generational-garbage-collection) to be useful.*GB*.
A gigabyte is 1024 [megabytes](/u/367f5f45f9800ccb#term-megabyte), or 1073741824
[bytes (1)](/u/4c6aaf4e0e0b7eb6#term-byte-1).
See [byte (1)](/u/4c6aaf4e0e0b7eb6#term-byte-1) for general information on this and
related quantities.good fit : The class of allocation policies which approximate best fit. Strict best fit may be costly to implement (depending on the details of the allocation mechanism), so some implementors approximate it, choosing a block which is close in size to the allocation request.
See also
[allocation policy](/u/9b03e2fad7c35ce0#term-allocation-policy), [best fit](/u/4c6aaf4e0e0b7eb6#term-best-fit), [next fit](/u/79d1d3e473607e01#term-next-fit), [worst fit](/u/355fa8e73e689b3a#term-worst-fit).
Related publication
[Wilson et al. (1995)](/u/80406cde1a6844cf#wil95).GPF : See
[General Protection Fault](#term-General-Protection-Fault).grain : The grain of a platform is the smallest alignment that is sufficient to accommodate all data accesses on that platform. Often this is a word or a small multiple of a word. Double precision floating point numbers often have the strictest alignment requirements.
See also
[alignment](/u/9b03e2fad7c35ce0#term-alignment), [word](/u/355fa8e73e689b3a#term-word).graph : A graph is a set of nodes together with a set of edges connecting nodes.
If the edges have direction like arrows (for example,
[references](/u/611c5a77bde93a2f#term-reference) in a graph of [objects](/u/f63e411ec871b42a#term-object)), then the
graph is said to be a *directed graph*.

*Directed graph.*
Relevance to memory management
Graphs are used to model [reachability](/u/611c5a77bde93a2f#term-reachable)
for [tracing garbage collection](/u/f992775ea91d0285#term-tracing-garbage-collection). The
[objects](/u/f63e411ec871b42a#term-object) are considered to form a graph, with the
nodes of the graph being the objects and the edges of the
graph being the references from one object to another.
Usually, there is a single, distinguished [root](/u/611c5a77bde93a2f#term-root) to
which the [mutator](/u/367f5f45f9800ccb#term-mutator) has *direct* access, and the
nodes strongly connected to it are the reachable modes.grey : In a tri-color marking scheme, gray objects are objects that are proved or assumed (see generational and condemn) to be reachable, but have not yet been scanned.
More precisely, gray objects have been noted reachable, but
must still be visited by the [collector (2)](/u/b107b7d39b75ccb0#term-collector-2) in order to
process their children.
Similar term
[gray list](#term-gray-list).
Opposite terms
[black](/u/4c6aaf4e0e0b7eb6#term-black), [white](/u/355fa8e73e689b3a#term-white).grey list : The gray list is the set of objects that a tracing garbage collector has noted reachable, but hasn’t scanned yet.
The gray list is so called because it corresponds to the set
of [gray](#term-gray) objects in the [tri-color marking](/u/f992775ea91d0285#term-tri-color-marking) model
of graph tracing. The gray list changes as the garbage
collector progresses.
Each gray object is [scanned](/u/699ff3e2d070663d#term-scan), and all
[white](/u/355fa8e73e689b3a#term-white) objects referred to by it become gray and are
added to the list. Scanning a gray object turns it
[black](/u/4c6aaf4e0e0b7eb6#term-black). When the gray list is empty, the tracing is
finished, and white objects may be [reclaimed](/u/611c5a77bde93a2f#term-reclaim).
The representation of the gray list is a key part of garbage
collector design. The size of the list is potentially
proportional to the size of the [heap](/u/5696710a733ccf6f#term-heap), and the
operation of finding the next gray object to scan must be
cheap.
See also
[Cheney scan](/u/b107b7d39b75ccb0#term-cheney-scan).