Once the memory locations of a given system have been marked appropriately, the collection phase may begin. The purpose of the phase is to return to available memory all those locations that were previously garbage. (Not used by any program but unavailable to any user) It is easy to pass through memory sequentially, examine each node in turn, and return unmarked nodes to available storage.
5.8.1 Stop And Copy Algorithm
Garbage collection approach that collects garbage and defragments the heap is called stop and copy. In stop and copy garbage collection algorithm, the heap is divided into two separate regions/spaces. At any point in time, all dynamically allocated object instances reside in only one of the two regions the active region. The other, inactive region is unoccupied.
Copying garbage collection does not really “collect” garbage. Rather, it moves all the live objects into one area, and the rest of the heap is available which is only garbage. Garbage collection in these systems is only implicit. While mark and compact collectors 3 use a separate marking phase that traverses the live data, copying collectors integrate the traversal of the data and the copying process, so that most objects need only be traversed once. Objects are moved to the contiguous destination area as they are reached by the traversal. The work needed is proportional to the amount of live data.
18a. A simple semi region garbage collector before garbage collection
When running program demands an allocation that will not fit in the unused area of the current region (semi space) or if the memory in the active region is exhausted, the program is suspended or stopped and the garbage collection algorithm is invoked to reclaim space. The stop and copy algorithm copies all of the live objects from the active region to the inactive region. As each object is copied, all references contained in that object are updated to reflect the new locations of the referenced objects.
No comments:
Post a Comment