<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
garbage	B-General_Concept
includes	O
data	O
,	O
objects	O
,	O
or	O
other	O
regions	O
of	O
the	O
memory	B-General_Concept
of	O
a	O
computer	O
system	O
(	O
or	O
other	O
system	O
resources	O
)	O
,	O
which	O
will	O
not	O
be	O
used	O
in	O
any	O
future	O
computation	O
by	O
the	O
system	O
,	O
or	O
by	O
a	O
program	O
running	O
on	O
it	O
.	O
</s>
<s>
Because	O
every	O
computer	O
system	O
has	O
a	O
finite	O
amount	O
of	O
memory	B-General_Concept
,	O
and	O
most	O
software	O
produces	O
garbage	B-General_Concept
,	O
it	O
is	O
frequently	O
necessary	O
to	O
deallocate	O
memory	B-General_Concept
that	O
is	O
occupied	O
by	O
garbage	B-General_Concept
and	O
return	O
it	O
to	O
the	O
heap	B-General_Concept
,	O
or	O
memory	B-General_Concept
pool	O
,	O
for	O
reuse	O
.	O
</s>
<s>
Garbage	B-General_Concept
is	O
generally	O
classified	O
into	O
two	O
types	O
:	O
syntactic	O
garbage	B-General_Concept
,	O
any	O
object	O
or	O
data	O
which	O
is	O
within	O
a	O
program	O
's	O
memory	B-General_Concept
space	O
but	O
unreachable	O
from	O
the	O
program	O
's	O
root	B-General_Concept
set	I-General_Concept
;	O
and	O
semantic	O
garbage	B-General_Concept
,	O
any	O
object	O
or	O
data	O
which	O
is	O
never	O
accessed	O
by	O
a	O
running	O
program	O
for	O
any	O
combination	O
of	O
program	O
inputs	O
.	O
</s>
<s>
Objects	O
and	O
data	O
which	O
are	O
not	O
garbage	B-General_Concept
are	O
said	O
to	O
be	O
live	O
.	O
</s>
<s>
Casually	O
stated	O
,	O
syntactic	O
garbage	B-General_Concept
is	O
data	O
that	O
cannot	O
be	O
reached	O
,	O
and	O
semantic	O
garbage	B-General_Concept
is	O
data	O
that	O
will	O
not	O
be	O
reached	O
.	O
</s>
<s>
More	O
precisely	O
,	O
syntactic	O
garbage	B-General_Concept
is	O
data	O
that	O
is	O
unreachable	O
due	O
to	O
the	O
reference	O
graph	O
(	O
there	O
is	O
no	O
path	O
to	O
it	O
)	O
,	O
which	O
can	O
be	O
determined	O
by	O
many	O
algorithms	O
,	O
as	O
discussed	O
in	O
tracing	B-General_Concept
garbage	I-General_Concept
collection	I-General_Concept
,	O
and	O
only	O
requires	O
analyzing	O
the	O
data	O
,	O
not	O
the	O
code	O
.	O
</s>
<s>
Semantic	O
garbage	B-General_Concept
is	O
data	O
that	O
will	O
not	O
be	O
accessed	O
,	O
either	O
because	O
it	O
is	O
unreachable	O
(	O
hence	O
also	O
syntactic	O
garbage	B-General_Concept
)	O
,	O
or	O
is	O
reachable	O
but	O
will	O
not	O
be	O
accessed	O
;	O
this	O
latter	O
requires	O
analysis	O
of	O
the	O
code	O
,	O
and	O
is	O
in	O
general	O
an	O
undecidable	O
problem	O
.	O
</s>
<s>
Syntactic	O
garbage	B-General_Concept
is	O
a	O
(	O
usually	O
strict	O
)	O
subset	O
of	O
semantic	O
garbage	B-General_Concept
,	O
as	O
it	O
is	O
entirely	O
possible	O
for	O
an	O
object	O
to	O
hold	O
a	O
reference	O
to	O
another	O
object	O
without	O
ever	O
using	O
that	O
object	O
.	O
</s>
<s>
In	O
the	O
following	O
simple	O
stack	B-Application
implementation	O
in	O
Java	B-Language
,	O
each	O
element	O
popped	O
from	O
the	O
stack	B-Application
becomes	O
semantic	O
garbage	B-General_Concept
once	O
there	O
are	O
no	O
outside	O
references	O
to	O
it	O
:	O
</s>
<s>
If	O
a	O
later	O
push	O
call	O
re-grows	O
the	O
stack	B-Application
to	O
the	O
previous	O
size	O
,	O
overwriting	O
this	O
last	O
reference	O
,	O
then	O
the	O
object	O
will	O
become	O
syntactic	O
garbage	B-General_Concept
,	O
because	O
it	O
can	O
never	O
be	O
accessed	O
again	O
,	O
and	O
will	O
be	O
eligible	O
for	O
garbage	B-General_Concept
collection	I-General_Concept
.	O
</s>
<s>
An	O
example	O
of	O
the	O
automatic	O
collection	O
of	O
syntactic	O
garbage	B-General_Concept
,	O
by	O
reference	B-General_Concept
counting	I-General_Concept
garbage	B-General_Concept
collection	I-General_Concept
,	O
can	O
be	O
produced	O
using	O
the	O
Python	B-Language
command-line	O
interpreter	B-Application
:	O
</s>
<s>
In	O
this	O
session	O
,	O
an	O
object	O
is	O
created	O
,	O
its	O
location	O
in	O
the	O
memory	B-General_Concept
is	O
displayed	O
,	O
and	O
the	O
only	O
reference	O
to	O
the	O
object	O
is	O
then	O
destroyed	O
—	O
there	O
is	O
no	O
way	O
to	O
ever	O
use	O
the	O
object	O
again	O
from	O
this	O
point	O
on	O
,	O
as	O
there	O
are	O
no	O
references	O
to	O
it	O
.	O
</s>
<s>
As	O
it	O
is	O
now	O
impossible	O
to	O
refer	O
to	O
the	O
object	O
,	O
the	O
object	O
has	O
become	O
useless	O
;	O
it	O
is	O
garbage	B-General_Concept
.	O
</s>
<s>
Since	O
Python	B-Language
uses	O
garbage	B-General_Concept
collection	I-General_Concept
,	O
it	O
automatically	O
deallocates	O
the	O
memory	B-General_Concept
that	O
was	O
used	O
for	O
the	O
object	O
so	O
that	O
it	O
may	O
be	O
used	O
again	O
:	O
</s>
<s>
The	O
instance	O
now	O
resides	O
at	O
the	O
memory	B-General_Concept
location	O
;	O
at	O
the	O
same	O
place	O
as	O
where	O
our	O
previous	O
object	O
,	O
the	O
instance	O
,	O
was	O
located	O
.	O
</s>
<s>
Since	O
the	O
instance	O
was	O
destroyed	O
,	O
freeing	O
up	O
the	O
memory	B-General_Concept
used	O
to	O
contain	O
it	O
,	O
the	O
interpreter	B-Application
creates	O
the	O
object	O
at	O
the	O
same	O
memory	B-General_Concept
location	O
as	O
before	O
,	O
making	O
good	O
use	O
of	O
the	O
available	O
resources	O
.	O
</s>
<s>
Garbage	B-General_Concept
consumes	O
heap	B-General_Concept
memory	B-General_Concept
,	O
and	O
thus	O
one	O
wishes	O
to	O
collect	O
it	O
(	O
to	O
minimize	O
memory	B-General_Concept
use	O
,	O
allow	O
faster	O
memory	B-General_Concept
allocation	I-General_Concept
,	O
and	O
prevent	O
out-of-memory	O
errors	O
by	O
reducing	O
heap	B-General_Concept
fragmentation	O
and	O
memory	B-General_Concept
use	O
)	O
.	O
</s>
<s>
However	O
,	O
collecting	O
garbage	B-General_Concept
takes	O
time	O
and	O
,	O
if	O
done	O
manually	O
,	O
requires	O
coding	O
overhead	O
.	O
</s>
<s>
Further	O
,	O
collecting	O
garbage	B-General_Concept
destroys	O
objects	O
and	O
thus	O
can	O
cause	O
calls	O
to	O
finalizers	B-Application
,	O
executing	O
potentially	O
arbitrary	O
code	O
at	O
an	O
arbitrary	O
point	O
in	O
the	O
program	O
's	O
execution	O
.	O
</s>
<s>
Incorrect	O
garbage	B-General_Concept
collection	I-General_Concept
(	O
deallocating	O
memory	B-General_Concept
that	O
is	O
not	O
garbage	B-General_Concept
)	O
,	O
primarily	O
due	O
to	O
errors	O
in	O
manual	O
garbage	B-General_Concept
collection	I-General_Concept
(	O
rather	O
than	O
errors	O
in	O
garbage	B-General_Concept
collectors	I-General_Concept
)	O
,	O
results	O
in	O
memory	B-Application
safety	I-Application
violations	O
(	O
that	O
often	O
create	O
security	O
holes	O
)	O
due	O
to	O
use	O
of	O
dangling	B-Error_Name
pointers	I-Error_Name
.	O
</s>
<s>
Syntactic	O
garbage	B-General_Concept
can	O
be	O
collected	O
automatically	O
,	O
and	O
garbage	B-General_Concept
collectors	I-General_Concept
have	O
been	O
extensively	O
studied	O
and	O
developed	O
.	O
</s>
<s>
Semantic	O
garbage	B-General_Concept
cannot	O
be	O
automatically	O
collected	O
in	O
general	O
,	O
and	O
thus	O
causes	O
memory	B-Error_Name
leaks	I-Error_Name
even	O
in	O
garbage-collected	O
languages	O
.	O
</s>
<s>
Detecting	O
and	O
eliminating	O
semantic	O
garbage	B-General_Concept
is	O
typically	O
done	O
using	O
a	O
specialized	O
debugging	O
tool	O
called	O
a	O
heap	B-General_Concept
profiler	O
,	O
which	O
allows	O
one	O
to	O
see	O
which	O
objects	O
are	O
live	O
and	O
how	O
they	O
are	O
reachable	O
,	O
enabling	O
one	O
to	O
remove	O
the	O
unintended	O
reference	O
.	O
</s>
<s>
The	O
problem	O
of	O
managing	O
the	O
deallocation	B-General_Concept
of	O
garbage	B-General_Concept
is	O
well-known	O
in	O
computer	B-General_Concept
science	I-General_Concept
.	O
</s>
<s>
Many	O
operating	B-General_Concept
systems	I-General_Concept
reclaim	O
the	O
memory	B-General_Concept
and	O
resources	O
used	O
by	O
a	O
process	O
or	O
program	O
when	O
it	O
terminates	O
.	O
</s>
<s>
Simple	O
or	O
short-lived	O
programs	O
which	O
are	O
designed	O
to	O
run	O
in	O
such	O
environments	O
can	O
exit	O
and	O
allow	O
the	O
operating	B-General_Concept
system	I-General_Concept
to	O
perform	O
any	O
necessary	O
reclamation	O
.	O
</s>
<s>
In	O
systems	O
or	O
programming	O
languages	O
with	O
manual	B-Application
memory	I-Application
management	I-Application
,	O
the	O
programmer	O
must	O
explicitly	O
arrange	O
for	O
memory	B-General_Concept
to	O
be	O
deallocated	O
when	O
it	O
is	O
no	O
longer	O
used	O
.	O
</s>
<s>
C	B-Language
and	O
C++	B-Language
are	O
two	O
well-known	O
languages	O
which	O
support	O
this	O
model	O
.	O
</s>
<s>
Garbage	B-General_Concept
collection	I-General_Concept
uses	O
various	O
algorithms	O
to	O
automatically	O
analyze	O
the	O
state	O
of	O
a	O
program	O
,	O
identify	O
garbage	B-General_Concept
,	O
and	O
deallocate	O
it	O
without	O
intervention	O
by	O
the	O
programmer	O
.	O
</s>
<s>
Many	O
modern	O
programming	O
languages	O
such	O
as	O
Java	B-Language
and	O
Haskell	B-Language
provide	O
automated	O
garbage	B-General_Concept
collection	I-General_Concept
.	O
</s>
<s>
However	O
,	O
it	O
is	O
not	O
a	O
recent	O
development	O
,	O
as	O
it	O
has	O
also	O
been	O
used	O
in	O
older	O
languages	O
such	O
as	O
LISP	B-Language
.	O
</s>
<s>
There	O
is	O
ongoing	O
research	O
to	O
type-theoretic	O
approaches	O
(	O
such	O
as	O
region	B-General_Concept
inference	I-General_Concept
)	O
to	O
identification	O
and	O
removal	O
of	O
garbage	B-General_Concept
from	O
a	O
program	O
.	O
</s>
