Content deleted Content added
No edit summary |
Patar knight (talk | contribs) Adding short description: "Computer software algorithm" |
||
(55 intermediate revisions by 41 users not shown) | |||
Line 1:
{{Short description|Computer software algorithm}}
'''Cheney's algorithm''', first described in a 1970 [[Association for Computing Machinery|ACM]] paper by C.J. Cheney, is a method of [[garbage collection (computer science)|garbage collection]] in computer software systems. In this scheme, the [[heap]] is divided into two equal halves, only one of which is in use at any one time. Garbage collection is performed by copying live objects from one semispace (the from-space) to the other (the to-space), which then becomes the new heap. The entire old heap is then discarded in one piece.▼
{{Use dmy dates|date=September 2021}}
{{more footnotes|date=April 2014}}
▲'''Cheney's algorithm''', first described in a 1970 [[Association for Computing Machinery|ACM]] paper by C.J. Cheney, is a [[stop and copy]] method of [[
Cheney's algorithm reclaims items as follows:
* '''
** If the object has not yet been moved to the to-space, this is done by creating an identical copy in the to-space, and then replacing the from-space version with a forwarding pointer to the to-space copy.
** If the object has already been moved to the to-space, simply update the reference from the forwarding pointer in from-space.
* '''Objects
▲* '''Objects on the to-space.''' The garbage collector examines all object references ''in the objects that have been migrated to the to-space'', and performs one of the above two actions on the referenced objects.
The
▲Once all to-space references have been examined and updated, garbage collection is complete.
The
▲The very clever thing about this algorithm is that it needs no stack and very little memory outside of the from-space and to-space; it needs only a pointer to the beginning of free space in the to-space, and a pointer to the next word in to-space that needs to be examined. For this reason, it's sometimes called a "two-finger" collector --- it only needs "two fingers" pointing into the to-space to keep track of its state. The data between the two fingers represents work remaining for it to do.
Because the strategy is to exhaust all live references, and then all references in referenced objects, this is known as a ''[[breadth-first]]'' list copying garbage collection scheme.▼
▲The aforementioned forwarding pointer (sometimes called a "broken heart") is used only during the garbage collection process: When a reference to an object already in to-space (thus having a forwarding pointer in from-space) is found, the reference can be updated quickly simply by updating its pointer to match the forwarding pointer.
▲Because the strategy is to exhaust all live references, and then all references in referenced objects, this is known as a ''breadth-first'' list copying garbage collection scheme.
== Semispace ==
Cheney based his work on the ''semispace'' garbage collector, which was published a year earlier by R.R. Fenichel and J.C. Yochelson.
== Equivalence to
Cheney's algorithm is an example of a [[tracing garbage collection#Tri-color marking|tri-color marking]] garbage collector. The first member of the gray set is the stack itself.
The algorithm moves any white objects (equivalent to objects in the from-space without forwarding pointers) to the gray set by copying them to the to-space.
When the scanning pointer reaches the free-space pointer, the gray set is empty, and the algorithm ends.
== References ==
* {{cite journal
|s2cid=36538112
|doi-access=free
* {{cite journal
|last2=Yochelson |first2=Jerome C.
|s2cid=36616954
}}▼
|doi-access=free
* {{cite journal
|last=Byers |first=Rick
|title=Garbage Collection Algorithms
|journal=Garbage Collection Algorithms
|volume=12 |issue=11 |year=2007 |pages=3–4
|url=http://courses.cs.washington.edu/courses/csep521/07wi/prj/rick.pdf
}}
== External links ==
* {{youtube|1uLzSXWWfDg|Understanding Android Runtime (Google I/O'19)}} - Android uses a variant of the semi-space garbage collector.
{{Memory management}}
[[Category:Automatic memory management]]
|