Ephemeron
Encyclopedia
For other uses, see Ephemera (disambiguation)
Ephemera (disambiguation)
Ephemera is transitory written and printed matter.Ephemera may also refer to:* Plectrohyla ephemera, a species of frog* Ephemera , a genus of mayfly* Ephemera , an all-female Norwegian group...

.

In computer science
Computer science
Computer science or computing science is the study of the theoretical foundations of information and computation and of practical techniques for their implementation and application in computer systems...

, finalization occurs when a garbage collector
Garbage collection (computer science)
In computer science, garbage collection is a form of automatic memory management. The garbage collector, or just collector, attempts to reclaim garbage, or memory occupied by objects that are no longer in use by the program...

 (GC) informs an application that an object is "almost collectable." It is used to help an application maintain its invariants
Invariant (computer science)
In computer science, a predicate is called an invariant to a sequence of operations provided that: if the predicate is true before starting the sequence, then it is true at the end of the sequence.-Use:...

. To make finalization more useful, "almost collectable" is defined in terms of a new class of objects, called ephemerons. Ephemerons are similar to weak pairs, but an object in an ephemeron's key field may be classed as "almost collectable" even if it is reachable from the ephemeron's value fields.

Description

An ephemeron is an object which refers strongly to its contents as long as the ephemeron's key is not garbage collected, and weakly from then on. Ephemerons solve a problem which is commonly found when trying to "attach" properties to objects by using a registry. When some property should be attached to an object, the property should (in terms of GC behavior) typically have the life-time that an instance variable of this object would have. However, this is complicated by having an external association between the object and its property such as:

property --------- registry --------- association --------- object

Here, the registry (a third party) will hold onto the association itself which would require manual removal from the registry (instead of automated garbage collection). While this problem can always be solved in any given concrete situation by using one of the various weak association types, choosing the 'right' kind of association depends on a variety of factors some of which can change dynamically.

Ephemerons solve this problem by defining that the 'contents' (value) of an ephemeron will be held strongly until the key is known to be garbage collected. From then on, the contents of the ephemeron will be held weakly. Therefore, the contents of an ephemeron can become eligible for garbage collection if and only if the key is garbage collectable which is the exact behavior which we would observe for an instance variable of the object.

History

Ephemerons were first invented by George Bosworth while he worked at Digitalk. They were used as the finalization mechanism in Visual Smalltalk Enterprise
Visual Smalltalk Enterprise
Visual Smalltalk Enterprise is a Smalltalk dialect that runs only on Microsoft Windows, and is the last in a long line of Smalltalk implementations first produced by Digitalk and now available through Cincom....

. Today ephemerons are available in most Smalltalk
Smalltalk
Smalltalk is an object-oriented, dynamically typed, reflective programming language. Smalltalk was created as the language to underpin the "new world" of computing exemplified by "human–computer symbiosis." It was designed and created in part for educational use, more so for constructionist...

dialects as well as many other languages with automatic garbage collection.

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK