Explain how a copying garbage collector works, and how can it be implemented using semispaces?

  • 0

    The copying garbage collector basically works by going through live objects and copying them into a specific region in the memory. This collector traces through all the live objects one by one. This entire process is performed in a single pass. Any object that is not copied in memory is garbage.
    The copying garbage collector can be implemented using semispaces by splitting the heap into two halves. Each half is a contiguous memory region. All the allocations are made from a single half of the heap only. When the specified heap is half full, the collector is immediately invoked and it copies the live objects into the other half of the heap. In this way the first half of the heap then only contains garbage and eventually is overwritten in the next pass.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.