<s>
An	O
ephemeron	B-General_Concept
is	O
a	O
data	O
structure	O
that	O
solves	O
two	O
related	O
problems	O
in	O
garbage	B-General_Concept
collected	I-General_Concept
systems	O
.	O
</s>
<s>
On	O
the	O
one	O
hand	O
,	O
an	O
ephemeron	B-General_Concept
provides	O
a	O
notification	O
when	O
some	O
object	O
is	O
about	O
to	O
be	O
collected	O
.	O
</s>
<s>
On	O
the	O
other	O
hand	O
,	O
an	O
ephemeron	B-General_Concept
allows	O
data	O
to	O
be	O
associated	O
with	O
some	O
object	O
without	O
creating	O
a	O
reference	O
to	O
that	O
object	O
that	O
will	O
prevent	O
the	O
object	O
from	O
being	O
collected	O
.	O
</s>
<s>
An	O
ephemeron	B-General_Concept
is	O
a	O
key-value	O
pair	O
,	O
where	O
the	O
key	O
is	O
the	O
object	O
that	O
the	O
ephemeron	B-General_Concept
guards	O
,	O
notifying	O
the	O
system	O
when	O
that	O
object	O
is	O
collectable	O
,	O
and	O
the	O
value	O
can	O
be	O
any	O
data	O
associated	O
with	O
the	O
object	O
such	O
as	O
a	O
property	O
list	O
,	O
and	O
which	O
may	O
be	O
empty	O
.	O
</s>
<s>
But	O
the	O
ephemeron	B-General_Concept
is	O
treated	O
specially	O
by	O
the	O
garbage	B-General_Concept
collector	I-General_Concept
.	O
</s>
<s>
The	O
value	O
field	O
is	O
not	O
traced	O
until	O
the	O
key	O
is	O
found	O
to	O
be	O
reachable	O
from	O
the	O
system	O
roots	O
other	O
than	O
through	O
ephemeron	B-General_Concept
keys	O
.	O
</s>
<s>
The	O
set	O
of	O
ephemerons	B-General_Concept
whose	O
keys	O
are	O
only	O
reachable	O
from	O
ephemeron	B-General_Concept
keys	O
are	O
then	O
holding	O
onto	O
keys	O
that	O
are	O
ready	O
to	O
be	O
collected	O
;	O
these	O
objects	O
are	O
not	O
reachable	O
from	O
the	O
roots	O
except	O
through	O
ephemerons	B-General_Concept
.	O
</s>
<s>
When	O
the	O
garbage	B-General_Concept
collector	I-General_Concept
detects	O
such	O
a	O
set	O
,	O
the	O
ephemerons	B-General_Concept
are	O
queued	O
for	O
notification	O
and	O
their	O
keys	O
and	O
values	O
are	O
traced	O
.	O
</s>
<s>
Hence	O
ephemerons	B-General_Concept
both	O
detect	O
objects	O
that	O
are	O
ready	O
for	O
collection	O
and	O
break	O
the	O
cycles	O
that	O
can	O
prevent	O
objects	O
from	O
being	O
collected	O
.	O
</s>
<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
finalization	B-Application
occurs	O
when	O
a	O
garbage	B-General_Concept
collector	I-General_Concept
(	O
GC	O
)	O
informs	O
an	O
application	O
that	O
an	O
object	O
is	O
"	O
almost	O
collectable	O
"	O
.	O
</s>
<s>
It	O
is	O
used	O
to	O
help	O
an	O
application	O
maintain	O
its	O
invariants	B-Application
.	O
</s>
<s>
Weak	B-General_Concept
references	I-General_Concept
may	O
be	O
used	O
by	O
a	O
garbage	B-General_Concept
collector	I-General_Concept
to	O
determine	O
the	O
objects	O
that	O
are	O
almost	O
collectable	O
.	O
</s>
<s>
Seen	O
both	O
as	O
key-value	O
pairs	O
,	O
the	O
main	O
difference	O
between	O
weak	B-General_Concept
references	I-General_Concept
and	O
an	O
ephemerons	B-General_Concept
is	O
the	O
way	O
the	O
garbage	B-General_Concept
collector	I-General_Concept
treats	O
them	O
.	O
</s>
<s>
For	O
weak	B-General_Concept
references	I-General_Concept
,	O
the	O
garbage	B-General_Concept
collector	I-General_Concept
always	O
follows	O
the	O
value	O
in	O
the	O
key-value	O
pair	O
.	O
</s>
<s>
For	O
ephemerons	B-General_Concept
,	O
instead	O
,	O
the	O
garbage	B-General_Concept
collector	I-General_Concept
does	O
n't	O
follow	O
the	O
value	O
but	O
queues	O
the	O
ephemeron	B-General_Concept
for	O
further	O
observation	O
at	O
a	O
second	O
stage	O
:	O
after	O
the	O
first	O
tracing	O
phase	O
is	O
done	O
,	O
it	O
runs	O
through	O
the	O
queue	O
looking	O
at	O
each	O
ephemeron	B-General_Concept
and	O
if	O
its	O
key	O
was	O
seen	O
,	O
then	O
it	O
follows	O
its	O
value	O
.	O
</s>
<s>
For	O
example	O
,	O
consider	O
a	O
key-value	O
pair	O
with	O
weak	B-General_Concept
references	I-General_Concept
where	O
the	O
key	O
is	O
an	O
object	O
and	O
the	O
value	O
is	O
a	O
set	O
of	O
properties	O
attached	O
to	O
the	O
object	O
.	O
</s>
<s>
If	O
an	O
ephemeron	B-General_Concept
was	O
used	O
instead	O
,	O
the	O
value	O
would	O
n't	O
have	O
been	O
followed	O
unless	O
the	O
object	O
was	O
proved	O
alive	O
,	O
solving	O
the	O
cycle	O
.	O
</s>
<s>
Ephemerons	B-General_Concept
are	O
similar	O
to	O
weak	O
pairs	O
,	O
but	O
an	O
object	O
in	O
an	O
ephemeron	B-General_Concept
's	O
key	O
field	O
may	O
be	O
classed	O
as	O
"	O
almost	O
collectable	O
"	O
even	O
if	O
it	O
is	O
reachable	O
from	O
the	O
ephemeron	B-General_Concept
's	O
value	O
fields	O
.	O
</s>
<s>
An	O
ephemeron	B-General_Concept
is	O
an	O
object	O
which	O
refers	O
strongly	O
to	O
its	O
contents	O
as	O
long	O
as	O
the	O
ephemeron	B-General_Concept
's	O
key	O
is	O
not	O
garbage	B-General_Concept
collected	I-General_Concept
,	O
and	O
weakly	O
from	O
then	O
on	O
.	O
</s>
<s>
Ephemerons	B-General_Concept
solve	O
a	O
problem	O
which	O
is	O
commonly	O
found	O
when	O
trying	O
to	O
"	O
attach	O
"	O
properties	O
to	O
objects	O
by	O
using	O
a	O
registry	O
.	O
</s>
<s>
Here	O
,	O
the	O
registry	O
(	O
a	O
third	O
party	O
)	O
will	O
hold	O
onto	O
the	O
association	O
itself	O
which	O
would	O
require	O
manual	O
removal	O
from	O
the	O
registry	O
(	O
instead	O
of	O
automated	O
garbage	B-General_Concept
collection	I-General_Concept
)	O
.	O
</s>
<s>
Ephemerons	B-General_Concept
solve	O
this	O
problem	O
by	O
defining	O
that	O
the	O
'	O
contents	O
 '	O
(	O
value	O
)	O
of	O
an	O
ephemeron	B-General_Concept
will	O
be	O
held	O
strongly	O
until	O
the	O
key	O
is	O
known	O
to	O
be	O
garbage	B-General_Concept
collected	I-General_Concept
.	O
</s>
<s>
From	O
then	O
on	O
,	O
the	O
contents	O
of	O
the	O
ephemeron	B-General_Concept
will	O
be	O
held	O
weakly	O
.	O
</s>
<s>
Therefore	O
,	O
the	O
contents	O
of	O
an	O
ephemeron	B-General_Concept
can	O
become	O
eligible	O
for	O
garbage	B-General_Concept
collection	I-General_Concept
if	O
and	O
only	O
if	O
the	O
key	O
is	O
garbage	O
collectable	O
which	O
is	O
the	O
exact	O
behavior	O
which	O
we	O
would	O
observe	O
for	O
an	O
instance	O
variable	O
of	O
the	O
object	O
.	O
</s>
<s>
Ephemerons	B-General_Concept
were	O
first	O
invented	O
by	O
George	O
Bosworth	O
while	O
he	O
worked	O
at	O
Digitalk	O
.	O
</s>
<s>
They	O
were	O
used	O
as	O
the	O
finalization	B-Application
mechanism	O
in	O
Visual	B-Language
Smalltalk	I-Language
Enterprise	I-Language
.	O
</s>
<s>
Today	O
ephemerons	B-General_Concept
are	O
available	O
in	O
most	O
Smalltalk	B-Application
dialects	O
as	O
well	O
as	O
many	O
other	O
languages	O
with	O
automatic	B-General_Concept
garbage	I-General_Concept
collection	I-General_Concept
.	O
</s>
<s>
Several	O
dialects	O
of	O
Smalltalk	B-Application
include	O
ephemerons	B-General_Concept
as	O
built-in	O
features	O
or	O
as	O
additional	O
packages	O
.	O
</s>
<s>
For	O
example	O
,	O
GNU	B-Application
Smalltalk	I-Application
and	O
Squeak	B-Operating_System
.	O
</s>
<s>
Lua	B-Language
does	O
not	O
contain	O
a	O
separate	O
ephemeron	B-General_Concept
construct	O
,	O
but	O
its	O
table	O
data	O
structures	O
may	O
be	O
set	O
to	O
holds	O
its	O
keys	O
,	O
values	O
,	O
or	O
both	O
in	O
a	O
weak	O
fashion	O
.	O
</s>
<s>
If	O
the	O
keys	O
are	O
held	O
weakly	O
,	O
but	O
values	O
are	O
held	O
strongly	O
,	O
the	O
table	O
will	O
act	O
like	O
an	O
ephemeron	B-General_Concept
.	O
</s>
<s>
Lua	B-Language
5.4	O
also	O
introduces	O
metatable	O
behavior	O
that	O
helps	O
to	O
construct	O
ephemeron-like	O
data	O
structures	O
.	O
</s>
<s>
Languages	O
such	O
as	O
C#	B-Application
,	O
F#	B-Operating_System
,	O
and	O
VB.NET	B-Language
,	O
as	O
of	O
.NET	B-Application
Framework	I-Application
4.0	O
,	O
have	O
support	O
in	O
the	O
class	O
.	O
</s>
<s>
The	O
underlying	O
ephemeron	B-General_Concept
mechanism	O
(	O
)	O
used	O
to	O
be	O
private	O
until	O
.NET	B-Application
6	O
.	O
</s>
<s>
An	O
implementation	O
of	O
an	O
OCaml	B-Language
ephemeron	B-General_Concept
type	O
was	O
presented	O
in	O
2014	O
and	O
added	O
to	O
the	O
standard	O
library	O
in	O
release	O
4.03	O
.	O
</s>
<s>
The	O
Racket	B-Operating_System
dialect	O
of	O
Lisp	B-Language
has	O
support	O
for	O
ephemerons	B-General_Concept
in	O
its	O
runtime	O
system	O
.	O
</s>
<s>
There	O
,	O
ephemerons	B-General_Concept
are	O
used	O
in	O
combination	O
with	O
weak	O
mappings	O
to	O
allow	O
the	O
garbage	B-General_Concept
collector	I-General_Concept
to	O
free	O
key-value	O
pairs	O
even	O
if	O
the	O
value	O
holds	O
a	O
reference	O
to	O
a	O
key	O
.	O
</s>
<s>
A	O
SRFI	O
(	O
Scheme	B-Language
Request	I-Language
for	I-Language
Implementation	I-Language
)	O
defines	O
an	O
API	O
for	O
Ephemerons	B-General_Concept
for	O
the	O
Scheme	O
language	O
.	O
</s>
