Content deleted Content added
Ash.taunk3 (talk | contribs) Added Sample Algorithm in pseudo code |
Patar knight (talk | contribs) Adding short description: "Computer software algorithm" |
||
(39 intermediate revisions by 27 users not shown) | |||
Line 1:
{{Short description|Computer software algorithm}}
{{
{{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:
* '''Object references on the stack.''' Object references on the stack are checked. One of the two following actions is taken for each object reference that points to an object in from-space:
** 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 in 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.
Once all to-space references have been examined and updated, garbage collection is complete.
The algorithm needs no stack and only two pointers outside of the from-space and to-space: 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. The
The forwarding pointer (sometimes called a "broken heart") is used only during the garbage collection process
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 ==
Line 59 ⟶ 24:
== Equivalence to tri-color abstraction ==
Cheney's algorithm is an example of a [[
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.
Line 67 ⟶ 32:
== References ==
* {{cite journal
|s2cid=36538112
|doi-access=free
* {{cite journal
|s2cid=36616954
|doi-access=free
▲ | first2 = Jerome C.
* {{cite journal
== 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]]
|