user9810241
user9810241

Reputation:

garbage collection concurrent

Why simple mark and sweep algorithm can't be done concurrently.

I have read that we need CMS(concurrent mark and sweep algorithm) for concurrent garbage collection that is more complex than simple mark and sweep algorithm but what is the problem with the simple one that we need CMS?

Upvotes: 0

Views: 109

Answers (1)

zch
zch

Reputation: 15278

The simplest reason is that marker can miss some reachable objects if the path to an object changes. Consider following program and scenario:

a = new Object();
b = new Object();
b.c = new Object();
// gc process marks a, nothing reachable from a
a.c = b.c;
b.c = null;
// gc process marks b, nothing reachable from b
// marking phase completes, a.c is not marked
// gc sweeps a.c
print a.c; // safety violation

Upvotes: 1

Related Questions