Stop and Copy
Object copy (Object p, Heap destination)
if (p == null)
return null;
if (p.forward == null)
q = destination.newInstance (p.class);
p.forward = q;
for each field f in p
if (f is a primitive type)
q.f = p.f;
else
q.f = copy (p.f, destination);
q.forward = null;
return p.forward;
Further Issues
1. Distinguishing pointers from integers.
2. Handling records of variable size.
3. Finding the root set.
4. Avoiding repeated copying of permanently live data.
5. Avoiding nasty pauses during collection.
The stop and copy algorithm incurs two costs
First cost is the algorithm requires that all live objects be copied every time garbage collection is invoked. If an application program has a large memory, the time required to copy all objects could be quite significant.
A second cost associated with stop-and-copy is that it requires twice as much memory as the program actually uses. When garbage collection is finished, at least half of the memory space is unused.
No comments:
Post a Comment