<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
manual	B-Application
memory	I-Application
management	I-Application
refers	O
to	O
the	O
usage	O
of	O
manual	O
instructions	O
by	O
the	O
programmer	O
to	O
identify	O
and	O
deallocate	O
unused	O
objects	O
,	O
or	O
garbage	B-General_Concept
.	O
</s>
<s>
Up	O
until	O
the	O
mid-1990s	O
,	O
the	O
majority	O
of	O
programming	O
languages	O
used	O
in	O
industry	O
supported	O
manual	B-Application
memory	I-Application
management	I-Application
,	O
though	O
garbage	B-General_Concept
collection	I-General_Concept
has	O
existed	O
since	O
1959	O
,	O
when	O
it	O
was	O
introduced	O
with	O
Lisp	B-Language
.	O
</s>
<s>
Today	O
,	O
however	O
,	O
languages	O
with	O
garbage	B-General_Concept
collection	I-General_Concept
such	O
as	O
Java	B-Language
are	O
increasingly	O
popular	O
and	O
the	O
languages	O
Objective-C	B-Language
and	O
Swift	B-Application
provide	O
similar	O
functionality	O
through	O
Automatic	B-Language
Reference	I-Language
Counting	I-Language
.	O
</s>
<s>
The	O
main	O
manually	O
managed	O
languages	O
still	O
in	O
widespread	O
use	O
today	O
are	O
C	B-Language
and	O
C++	B-Language
–	O
see	O
C	B-Language
dynamic	I-Language
memory	I-Language
allocation	I-Language
.	O
</s>
<s>
Many	O
programming	O
languages	O
use	O
manual	O
techniques	O
to	O
determine	O
when	O
to	O
allocate	O
a	O
new	B-Language
object	O
from	O
the	O
free	O
store	O
.	O
</s>
<s>
C	B-Language
uses	O
the	O
malloc	B-Language
function	O
;	O
C++	B-Language
and	O
Java	B-Language
use	O
the	O
new	B-Language
operator	O
;	O
and	O
many	O
other	O
languages	O
(	O
such	O
as	O
Python	O
)	O
allocate	O
all	O
objects	O
from	O
the	O
free	O
store	O
.	O
</s>
<s>
is	O
garbage	B-General_Concept
)	O
,	O
and	O
arranging	O
for	O
its	O
underlying	O
storage	O
to	O
be	O
returned	O
to	O
the	O
free	O
store	O
for	O
re-use	O
.	O
</s>
<s>
In	O
manual	O
memory	B-General_Concept
allocation	I-General_Concept
,	O
this	O
is	O
also	O
specified	O
manually	O
by	O
the	O
programmer	O
;	O
via	O
functions	O
such	O
as	O
free( )	O
in	O
C	B-Language
,	O
or	O
the	O
delete	B-Language
operator	O
in	O
C++	B-Language
–	O
this	O
contrasts	O
with	O
automatic	O
destruction	O
of	O
objects	O
held	O
in	O
automatic	B-General_Concept
variables	I-General_Concept
,	O
notably	O
(	O
non-static	O
)	O
local	O
variables	O
of	O
functions	O
,	O
which	O
are	O
destroyed	O
at	O
the	O
end	O
of	O
their	O
scope	O
in	O
C	B-Language
and	O
C++	B-Language
.	O
</s>
<s>
Manual	B-Application
memory	I-Application
management	I-Application
is	O
known	O
to	O
enable	O
several	O
major	O
classes	O
of	O
bugs	O
into	O
a	O
program	O
when	O
used	O
incorrectly	O
,	O
notably	O
violations	O
of	O
memory	B-Application
safety	I-Application
or	O
memory	B-Error_Name
leaks	I-Error_Name
.	O
</s>
<s>
When	O
an	O
unused	O
object	O
is	O
never	O
released	O
back	O
to	O
the	O
free	O
store	O
,	O
this	O
is	O
known	O
as	O
a	O
memory	B-Error_Name
leak	I-Error_Name
.	O
</s>
<s>
In	O
some	O
cases	O
,	O
memory	B-Error_Name
leaks	I-Error_Name
may	O
be	O
tolerable	O
,	O
such	O
as	O
a	O
program	O
which	O
"	O
leaks	O
"	O
a	O
bounded	O
amount	O
of	O
memory	O
over	O
its	O
lifetime	O
,	O
or	O
a	O
short-running	O
program	O
which	O
relies	O
on	O
an	O
operating	B-General_Concept
system	I-General_Concept
to	O
deallocate	O
its	O
resources	O
when	O
it	O
terminates	O
.	O
</s>
<s>
However	O
,	O
in	O
many	O
cases	O
memory	B-Error_Name
leaks	I-Error_Name
occur	O
in	O
long-running	O
programs	O
,	O
and	O
in	O
such	O
cases	O
an	O
unbounded	O
amount	O
of	O
memory	O
is	O
leaked	O
.	O
</s>
<s>
Catastrophic	O
failure	O
of	O
the	O
dynamic	B-General_Concept
memory	I-General_Concept
management	I-General_Concept
system	O
may	O
result	O
when	O
an	O
object	O
's	O
backing	O
memory	O
is	O
deleted	O
out	O
from	O
under	O
it	O
more	O
than	O
once	O
;	O
an	O
object	O
is	O
explicitly	O
destroyed	O
more	O
than	O
once	O
;	O
when	O
,	O
while	O
using	O
a	O
pointer	O
to	O
manipulate	O
an	O
object	O
not	O
allocated	O
on	O
the	O
free	O
store	O
,	O
a	O
programmer	O
attempts	O
to	O
release	O
said	O
pointer	O
's	O
target	O
object	O
's	O
backing	O
memory	O
;	O
or	O
when	O
,	O
while	O
manipulating	O
an	O
object	O
via	O
a	O
pointer	O
to	O
another	O
,	O
arbitrary	O
area	O
of	O
memory	O
managed	O
by	O
an	O
unknown	O
external	O
task	O
,	O
thread	O
,	O
or	O
process	O
,	O
a	O
programmer	O
corrupts	O
that	O
object	O
's	O
state	O
,	O
possibly	O
in	O
such	O
a	O
way	O
as	O
to	O
write	O
outside	O
of	O
its	O
bounds	O
and	O
corrupt	O
its	O
memory	B-General_Concept
management	I-General_Concept
data	O
.	O
</s>
<s>
The	O
result	O
of	O
such	O
actions	O
can	O
include	O
heap	B-General_Concept
corruption	I-General_Concept
,	O
premature	O
destruction	O
of	O
a	O
different	O
(	O
and	O
newly	O
created	O
)	O
object	O
which	O
happens	O
to	O
occupy	O
the	O
same	O
location	O
in	O
memory	O
as	O
the	O
multiply	O
deleted	O
object	O
,	O
program	O
crashes	O
due	O
to	O
a	O
segmentation	B-Error_Name
fault	I-Error_Name
(	O
violation	O
of	O
memory	B-General_Concept
protection	I-General_Concept
,	O
)	O
and	O
other	O
forms	O
of	O
undefined	B-Language
behavior	I-Language
.	O
</s>
<s>
Pointers	O
to	O
deleted	O
objects	O
become	O
wild	B-Error_Name
pointers	I-Error_Name
if	O
used	O
post-deletion	O
;	O
attempting	O
to	O
use	O
such	O
pointers	O
can	O
result	O
in	O
difficult-to-diagnose	O
bugs	O
.	O
</s>
<s>
Languages	O
which	O
exclusively	O
use	O
garbage	B-General_Concept
collection	I-General_Concept
are	O
known	O
to	O
avoid	O
the	O
last	O
two	O
classes	O
of	O
defects	O
.	O
</s>
<s>
Memory	B-Error_Name
leaks	I-Error_Name
can	O
still	O
occur	O
(	O
and	O
bounded	O
leaks	O
frequently	O
occur	O
with	O
generational	O
or	O
conservative	O
garbage	B-General_Concept
collection	I-General_Concept
)	O
,	O
but	O
are	O
generally	O
less	O
severe	O
than	O
memory	B-Error_Name
leaks	I-Error_Name
in	O
manual	O
systems	O
.	O
</s>
<s>
Manual	B-Application
memory	I-Application
management	I-Application
has	O
one	O
correctness	O
advantage	O
,	O
which	O
is	O
that	O
it	O
allows	O
automatic	O
resource	O
management	O
via	O
the	O
Resource	B-Application
Acquisition	I-Application
Is	I-Application
Initialization	I-Application
(	O
RAII	B-Application
)	O
paradigm	O
.	O
</s>
<s>
This	O
arises	O
when	O
objects	O
own	O
scarce	O
system	B-General_Concept
resources	I-General_Concept
(	O
like	O
graphics	O
resources	O
,	O
file	O
handles	O
,	O
or	O
database	O
connections	O
)	O
which	O
must	O
be	O
relinquished	O
when	O
an	O
object	O
is	O
destroyed	O
–	O
when	O
the	O
lifetime	O
of	O
the	O
resource	O
ownership	O
should	O
be	O
tied	O
to	O
the	O
lifetime	O
of	O
the	O
object	O
.	O
</s>
<s>
Languages	O
with	O
manual	O
management	O
can	O
arrange	O
this	O
by	O
acquiring	O
the	O
resource	O
during	O
object	O
initialization	O
(	O
in	O
the	O
constructor	O
)	O
,	O
and	O
releasing	O
during	O
object	O
destruction	O
(	O
in	O
the	O
destructor	B-Language
)	O
,	O
which	O
occurs	O
at	O
a	O
precise	O
time	O
.	O
</s>
<s>
This	O
is	O
known	O
as	O
Resource	B-Application
Acquisition	I-Application
Is	I-Application
Initialization	I-Application
.	O
</s>
<s>
This	O
can	O
also	O
be	O
used	O
with	O
deterministic	O
reference	B-General_Concept
counting	I-General_Concept
.	O
</s>
<s>
In	O
C++	B-Language
,	O
this	O
ability	O
is	O
put	O
to	O
further	O
use	O
to	O
automate	O
memory	B-General_Concept
deallocation	I-General_Concept
within	O
an	O
otherwise-manual	O
framework	O
,	O
use	O
of	O
the	O
shared_ptr	O
template	O
in	O
the	O
language	O
's	O
standard	O
library	O
to	O
perform	O
memory	B-General_Concept
management	I-General_Concept
is	O
a	O
common	O
paradigm	O
.	O
</s>
<s>
This	O
approach	O
is	O
not	O
usable	O
in	O
most	O
garbage	B-General_Concept
collected	I-General_Concept
languages	O
–	O
notably	O
tracing	O
garbage	B-General_Concept
collectors	I-General_Concept
or	O
more	O
advanced	O
reference	B-General_Concept
counting	I-General_Concept
–	O
due	O
to	O
finalization	O
being	O
non-deterministic	O
,	O
and	O
sometimes	O
not	O
occurring	O
at	O
all	O
.	O
</s>
<s>
That	O
is	O
,	O
it	O
is	O
difficult	O
to	O
define	O
(	O
or	O
determine	O
)	O
when	O
or	O
if	O
a	O
finalizer	B-Application
method	O
might	O
be	O
called	O
;	O
this	O
is	O
commonly	O
known	O
as	O
the	O
finalizer	B-Application
problem	O
.	O
</s>
<s>
Java	B-Language
and	O
other	O
GC	O
'd	O
languages	O
frequently	O
use	O
manual	O
management	O
for	O
scarce	O
system	B-General_Concept
resources	I-General_Concept
besides	O
memory	O
via	O
the	O
dispose	B-Application
pattern	I-Application
:	O
any	O
object	O
which	O
manages	O
resources	O
is	O
expected	O
to	O
implement	O
the	O
dispose( )	O
method	O
,	O
which	O
releases	O
any	O
such	O
resources	O
and	O
marks	O
the	O
object	O
as	O
inactive	O
.	O
</s>
<s>
Programmers	O
are	O
expected	O
to	O
invoke	O
dispose( )	O
manually	O
as	O
appropriate	O
to	O
prevent	O
"	O
leaking	O
"	O
of	O
scarce	O
graphics	O
resources	O
.	O
</s>
<s>
Depending	O
on	O
the	O
finalize( )	O
method	O
(	O
how	O
Java	B-Language
implements	O
finalizers	B-Application
)	O
to	O
release	O
graphics	O
resources	O
is	O
widely	O
viewed	O
as	O
poor	O
programming	O
practice	O
among	O
Java	B-Language
programmers	O
,	O
and	O
similarly	O
the	O
analogous	O
__del__( )	O
method	O
in	O
Python	O
cannot	O
be	O
relied	O
on	O
for	O
releasing	O
resources	O
.	O
</s>
<s>
For	O
stack	O
resources	O
(	O
resources	O
acquired	O
and	O
released	O
within	O
a	O
single	O
block	O
of	O
code	O
)	O
,	O
this	O
can	O
be	O
automated	O
by	O
various	O
language	O
constructs	O
,	O
such	O
as	O
Python	O
's	O
with	O
,	O
C#'s	O
using	O
or	O
Java	B-Language
's	O
try-with-resources	O
.	O
</s>
<s>
Many	O
advocates	O
of	O
manual	B-Application
memory	I-Application
management	I-Application
argue	O
that	O
it	O
affords	O
superior	O
performance	O
when	O
compared	O
to	O
automatic	O
techniques	O
such	O
as	O
garbage	B-General_Concept
collection	I-General_Concept
.	O
</s>
<s>
Manual	O
allocation	O
frequently	O
has	O
superior	O
locality	B-General_Concept
of	I-General_Concept
reference	I-General_Concept
.	O
</s>
<s>
Memory	O
systems	O
can	O
and	O
do	O
frequently	O
"	O
thrash	O
"	O
as	O
the	O
size	O
of	O
a	O
program	O
's	O
working	B-General_Concept
set	I-General_Concept
approaches	O
the	O
size	O
of	O
available	O
memory	O
;	O
unused	O
objects	O
in	O
a	O
garbage-collected	O
system	O
remain	O
in	O
an	O
unreclaimed	O
state	O
for	O
longer	O
than	O
in	O
manually	O
managed	O
systems	O
,	O
because	O
they	O
are	O
not	O
immediately	O
reclaimed	O
,	O
increasing	O
the	O
effective	O
working	B-General_Concept
set	I-General_Concept
size	O
.	O
</s>
<s>
Calls	O
to	O
delete	B-Language
and	O
such	O
incur	O
an	O
overhead	O
each	O
time	O
they	O
are	O
made	O
,	O
this	O
overhead	O
can	O
be	O
amortized	O
in	O
garbage	B-General_Concept
collection	I-General_Concept
cycles	O
.	O
</s>
<s>
This	O
is	O
especially	O
true	O
of	O
multithreaded	O
applications	O
,	O
where	O
delete	B-Language
calls	O
must	O
be	O
synchronized	O
.	O
</s>
<s>
Some	O
garbage	B-General_Concept
collection	I-General_Concept
schemes	O
,	O
such	O
as	O
those	O
with	O
heap	B-General_Concept
compaction	I-General_Concept
,	O
can	O
maintain	O
the	O
free	O
store	O
as	O
a	O
simple	O
array	O
of	O
memory	O
(	O
as	O
opposed	O
to	O
the	O
complicated	O
implementations	O
required	O
by	O
manual	O
management	O
schemes	O
)	O
.	O
</s>
<s>
Latency	O
is	O
a	O
debated	O
point	O
that	O
has	O
changed	O
over	O
time	O
,	O
with	O
early	O
garbage	B-General_Concept
collectors	I-General_Concept
and	O
simple	O
implementations	O
performing	O
very	O
poorly	O
compared	O
to	O
manual	B-Application
memory	I-Application
management	I-Application
,	O
but	O
sophisticated	O
modern	O
garbage	B-General_Concept
collectors	I-General_Concept
often	O
performing	O
as	O
well	O
or	O
better	O
than	O
manual	B-Application
memory	I-Application
management	I-Application
.	O
</s>
<s>
Manual	O
allocation	O
does	O
not	O
suffer	O
from	O
the	O
long	O
"	O
pause	O
"	O
times	O
that	O
occur	O
in	O
simple	O
stop-the-world	O
garbage	B-General_Concept
collection	I-General_Concept
,	O
although	O
modern	O
garbage	B-General_Concept
collectors	I-General_Concept
have	O
collection	O
cycles	O
which	O
are	O
often	O
not	O
noticeable	O
.	O
</s>
<s>
Manual	B-Application
memory	I-Application
management	I-Application
and	O
garbage	B-General_Concept
collection	I-General_Concept
both	O
suffer	O
from	O
potentially	O
unbounded	O
deallocation	B-General_Concept
times	O
–	O
manual	B-Application
memory	I-Application
management	I-Application
because	O
deallocating	O
a	O
single	O
object	O
may	O
require	O
deallocating	O
its	O
members	O
,	O
and	O
recursively	O
its	O
members	O
 '	O
members	O
,	O
etc.	O
,	O
while	O
garbage	B-General_Concept
collection	I-General_Concept
may	O
have	O
long	O
collection	O
cycles	O
.	O
</s>
<s>
This	O
is	O
especially	O
an	O
issue	O
in	O
real	B-General_Concept
time	I-General_Concept
systems	O
,	O
where	O
unbounded	O
collection	O
cycles	O
are	O
generally	O
unacceptable	O
;	O
real-time	O
garbage	B-General_Concept
collection	I-General_Concept
is	O
possible	O
by	O
pausing	O
the	O
garbage	B-General_Concept
collector	I-General_Concept
,	O
while	O
real-time	O
manual	B-Application
memory	I-Application
management	I-Application
requires	O
avoiding	O
large	O
deallocations	B-General_Concept
,	O
or	O
manually	O
pausing	O
deallocation	B-General_Concept
.	O
</s>
