Jump to content

Stop and Copy Garbage Collection Algorithm

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 208.77.212.41 (talk) at 18:01, 12 June 2012 (Looks like Cheney's algorithm to me). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

The Stop and Copy Garbage Collection Algorithm (also known as the semi-space collector) is an approach to garbage collection. The algorithm splits the program's memory heap into two equal partitions, a "from space" and a "to space" (sometimes called the "live partition" and "dead partition" respectively). The "from space" holds all active objects, whereas the "to space" is initially empty.

When all memory in the "from space" has been exhausted by the program, execution is suspended and the Stop and Copy Collector is invoked. The algorithm first copies all live objects from the "from space" to the "to space". Any handles or references to these live objects are updated to reflect their new location in memory.[1]

After the copy is completed, the active roles of the 2 partitions are reversed; The dead partition now holsters the alive memory objects, and the dead partition is inactive.[2] The algorithm works by copying only the live elements from the live partition over to the new area, and thus, the garbage objects are left behind to be overwritten at the next invocation of the algorithm.[3]

As the Copy Algorithm copies the live objects from one side to the other, it places them contiguously in memory, and therefore, by default, de-fragments the memory.

Drawbacks of the Copy Algorithm are as follows: Firstly, the algorithm requires that all live objects be copied each time garbage collection is required, which could lead to long wait times if a program has a large memory heap, with many live/active objects.[4] Secondly, we see that the Copy Algorithm requires double the amount of memory as the program will request. In the normal operations of the program, only half of this memory is being used, as the other half is sitting unallocated waiting for garbage collection to be invoked. [5]

References

  1. ^ http://www.brpreiss.com/books/opus5/html/page426.html
  2. ^ Stallins, William (2012). Operating Systems - Internals and Design Prinicples - 7th Edition. Pearson Education Inc. ISBN 978-0-13-230998-1.
  3. ^ http://www.javacoffeebreak.com/articles/thinkinginjava/abitaboutgarbagecollection.html
  4. ^ http://www.brpreiss.com/books/opus5/html/page426.html
  5. ^ http://www.brpreiss.com/books/opus5/html/page426.html