<s>
Automatic	B-Language
Reference	I-Language
Counting	I-Language
(	O
ARC	O
)	O
is	O
a	O
memory	B-General_Concept
management	I-General_Concept
feature	O
of	O
the	O
Clang	B-Application
compiler	B-Language
providing	O
automatic	B-Language
reference	I-Language
counting	I-Language
for	O
the	O
Objective-C	B-Language
and	O
Swift	B-Application
programming	I-Application
languages	I-Application
.	O
</s>
<s>
At	O
compile	B-Language
time	O
,	O
it	O
inserts	O
into	O
the	O
object	B-Language
code	I-Language
messages	O
retain	O
and	O
release	O
which	O
increase	O
and	O
decrease	O
the	O
reference	B-General_Concept
count	I-General_Concept
at	O
run	O
time	O
,	O
marking	O
for	O
deallocation	B-General_Concept
those	O
objects	O
when	O
the	O
number	O
of	O
references	O
to	O
them	O
reaches	O
zero	O
.	O
</s>
<s>
ARC	O
differs	O
from	O
tracing	B-General_Concept
garbage	I-General_Concept
collection	I-General_Concept
in	O
that	O
there	O
is	O
no	O
background	O
process	O
that	O
deallocates	O
the	O
objects	O
asynchronously	O
at	O
runtime	O
.	O
</s>
<s>
Unlike	O
tracing	B-General_Concept
garbage	I-General_Concept
collection	I-General_Concept
,	O
ARC	O
does	O
not	O
handle	O
reference	O
cycles	O
automatically	O
.	O
</s>
<s>
Strong	O
cross-references	O
can	O
accordingly	O
create	O
deadlocks	B-Operating_System
and	O
memory	B-Error_Name
leaks	I-Error_Name
.	O
</s>
<s>
It	O
is	O
up	O
to	O
the	O
developer	O
to	O
break	O
cycles	O
by	O
using	O
weak	B-General_Concept
references	I-General_Concept
.	O
</s>
<s>
Apple	O
Inc	O
.	O
deploys	O
ARC	O
in	O
their	O
operating	O
systems	O
,	O
such	O
as	O
macOS	B-Application
(	O
)	O
and	O
iOS	B-Application
.	O
</s>
<s>
Limited	O
support	O
(	O
ARCLite	O
)	O
has	O
been	O
available	O
since	O
Snow	B-Device
Leopard	I-Device
and	O
iOS	B-Operating_System
4	I-Operating_System
,	O
with	O
complete	O
support	O
following	O
in	O
Lion	B-Application
and	O
iOS	B-Operating_System
5	I-Operating_System
.	O
</s>
<s>
Garbage	O
collection	O
was	O
declared	O
deprecated	O
in	O
Mountain	O
Lion	B-Application
,	O
in	O
favor	O
of	O
ARC	O
,	O
and	O
removed	O
from	O
the	O
Objective-C	B-Language
runtime	B-Library
library	I-Library
in	O
macOS	B-Operating_System
Sierra	I-Operating_System
.	O
</s>
<s>
The	O
following	O
rules	O
are	O
enforced	O
by	O
the	O
compiler	B-Language
when	O
ARC	O
is	O
turned	O
on	O
:	O
</s>
<s>
Instead	O
,	O
the	O
compiler	B-Language
inserts	O
these	O
messages	O
at	O
compile	B-Language
time	O
automatically	O
,	O
including	O
[	O
super	O
dealloc ]	O
when	O
dealloc	O
is	O
overridden	O
.	O
</s>
<s>
Programs	O
must	O
use	O
special	O
casts	O
,	O
or	O
calls	O
to	O
special	O
functions	O
,	O
to	O
tell	O
the	O
compiler	B-Language
more	O
information	O
about	O
an	O
object	O
's	O
lifetime	O
.	O
</s>
<s>
Zeroing	O
weak	B-General_Concept
references	I-General_Concept
is	O
a	O
feature	O
in	O
Objective-C	B-Language
ARC	O
that	O
automatically	O
clears	O
(	O
sets	O
to	O
nil	O
)	O
weak-reference	O
local	O
variables	O
,	O
instance	O
variables	O
,	O
and	O
declared	O
properties	O
immediately	O
before	O
the	O
object	O
being	O
pointed	O
to	O
starts	O
deallocating	O
.	O
</s>
<s>
This	O
ensures	O
that	O
the	O
pointer	O
goes	O
to	O
either	O
a	O
valid	O
object	O
or	O
nil	O
,	O
and	O
avoids	O
dangling	B-Error_Name
pointers	I-Error_Name
.	O
</s>
<s>
Prior	O
to	O
the	O
introduction	O
of	O
this	O
feature	O
,	O
"	O
weak	B-General_Concept
references	I-General_Concept
"	O
referred	O
to	O
references	O
that	O
were	O
not	O
retaining	O
,	O
but	O
were	O
not	O
set	O
to	O
nil	O
when	O
the	O
object	O
they	O
pointed	O
to	O
was	O
deallocated	O
(	O
equivalent	O
to	O
unsafe_unretained	O
in	O
ARC	O
)	O
,	O
thus	O
possibly	O
leading	O
to	O
a	O
dangling	B-Error_Name
pointer	I-Error_Name
.	O
</s>
<s>
The	O
programmer	O
typically	O
had	O
to	O
ensure	O
that	O
all	O
possible	O
weak	B-General_Concept
references	I-General_Concept
to	O
an	O
object	O
were	O
set	O
to	O
nil	O
manually	O
when	O
it	O
was	O
being	O
deallocated	O
.	O
</s>
<s>
Zeroing	O
weak	B-General_Concept
references	I-General_Concept
obviates	O
the	O
need	O
to	O
do	O
this	O
.	O
</s>
<s>
Zeroing	O
weak	B-General_Concept
references	I-General_Concept
are	O
indicated	O
by	O
using	O
the	O
declared	O
property	O
attribute	O
weak	O
or	O
by	O
using	O
the	O
variable	O
attribute	O
__weak	O
.	O
</s>
<s>
Zeroing	O
weak	B-General_Concept
references	I-General_Concept
are	O
only	O
available	O
in	O
Mac	B-Application
OS	I-Application
X	I-Application
Lion	I-Application
(	O
10.7	B-Application
)	O
or	O
later	O
and	O
iOS	B-Operating_System
5	I-Operating_System
or	O
later	O
,	O
because	O
they	O
require	O
additional	O
support	O
from	O
the	O
Objective-C	B-Language
runtime	O
.	O
</s>
<s>
However	O
,	O
some	O
OS	O
X	O
classes	O
do	O
not	O
currently	O
support	O
weak	B-General_Concept
references	I-General_Concept
.	O
</s>
<s>
Code	O
that	O
uses	O
ARC	O
but	O
needs	O
to	O
support	O
versions	O
of	O
the	O
OS	O
older	O
than	O
those	O
above	O
cannot	O
use	O
zeroing	O
weak	B-General_Concept
references	I-General_Concept
,	O
and	O
therefore	O
must	O
use	O
unsafe_unretained	O
weak	B-General_Concept
references	I-General_Concept
.	O
</s>
<s>
There	O
exists	O
a	O
third-party	O
library	O
called	O
PLWeakCompatibility	O
that	O
allows	O
one	O
to	O
use	O
zeroing	O
weak	B-General_Concept
references	I-General_Concept
even	O
on	O
these	O
older	O
OS	O
versions	O
.	O
</s>
<s>
Xcode	B-Operating_System
4.2	O
or	O
later	O
provides	O
a	O
way	O
to	O
convert	O
code	O
to	O
ARC	O
.	O
</s>
<s>
As	O
of	O
Xcode	B-Operating_System
4.5	O
,	O
it	O
is	O
found	O
by	O
choosing	O
Edit	O
>	O
Refactor	O
>	O
Convert	O
to	O
Objective-C	B-Language
ARC	O
...	O
</s>
<s>
Although	O
Xcode	B-Operating_System
will	O
automatically	O
convert	O
most	O
code	O
,	O
some	O
code	O
may	O
have	O
to	O
be	O
converted	O
manually	O
.	O
</s>
<s>
Xcode	B-Operating_System
will	O
inform	O
the	O
developer	O
when	O
more	O
complex	O
use	O
cases	O
arise	O
,	O
such	O
as	O
when	O
a	O
variable	O
is	O
declared	O
inside	O
an	O
autorelease	O
pool	O
and	O
used	O
outside	O
it	O
or	O
when	O
two	O
objects	O
need	O
to	O
be	O
toll-free	O
bridged	O
with	O
special	O
casts	O
.	O
</s>
<s>
In	O
Swift	B-Application
,	O
references	O
to	O
objects	O
are	O
strong	O
,	O
unless	O
they	O
are	O
declared	O
weak	O
or	O
unowned	O
.	O
</s>
<s>
Swift	B-Application
requires	O
explicit	O
handling	O
of	O
nil	O
with	O
the	O
Optional	O
type	O
:	O
a	O
value	O
type	O
that	O
can	O
either	O
have	O
a	O
value	O
or	O
be	O
nil	O
.	O
</s>
<s>
An	O
Optional	O
type	O
must	O
be	O
handled	O
by	O
"	O
unwrapping	O
"	O
it	O
with	O
a	O
conditional	B-Language
statement	I-Language
,	O
allowing	O
safe	O
usage	O
of	O
the	O
value	O
,	O
if	O
present	O
.	O
</s>
<s>
Accordingly	O
,	O
a	O
strong	B-General_Concept
reference	I-General_Concept
to	O
an	O
object	O
can	O
be	O
of	O
both	O
Optional	O
and	O
non-Optional	O
type	O
(	O
optionality	O
and	O
reference	O
strength	O
are	O
different	O
,	O
albeit	O
related	O
,	O
concepts	O
)	O
.	O
</s>
<s>
A	O
weak	B-General_Concept
reference	I-General_Concept
is	O
always	O
of	O
type	O
Optional	O
,	O
as	O
the	O
object	O
can	O
be	O
deallocated	O
and	O
the	O
reference	O
automatically	O
be	O
set	O
to	O
nil	O
.	O
</s>
<s>
Unowned	O
references	O
are	O
like	O
weak	B-General_Concept
references	I-General_Concept
but	O
are	O
not	O
set	O
to	O
nil	O
automatically	O
by	O
ARC	O
.	O
</s>
<s>
Swift	B-Application
also	O
differs	O
from	O
Objective-C	B-Language
in	O
its	O
usage	O
and	O
encouragement	O
of	O
value	O
types	O
instead	O
of	O
reference	B-Language
types	I-Language
.	O
</s>
<s>
Most	O
types	O
in	O
the	O
Swift	B-Application
standard	O
library	O
are	O
value	O
types	O
and	O
they	O
are	O
copied	O
by	O
value	O
,	O
whereas	O
classes	O
and	O
closures	B-Language
are	O
reference	B-Language
types	I-Language
and	O
passed	O
by	O
reference	O
.	O
</s>
