Consider the following Cool program:
class C {
next : C;
set(n : C): C { { next <- n; self; } };
};
class Main{
main(): Int {
let x : C in {
let o1 : C <- new C, o2 : C <- new C, o3 : C <- new C,
o4 : C <- new C, o5 : C <- new C, o6 : C <- new C in
{ o1.set(o2); o2.set(o3); o3.set(o1); o5.set(o6); x <- o5; };
(*GC*)
0;
}
};
};
Assume that a garbage collection occurs at the line marked "GC" and that no garbage is collected before that point. How many objects
of type C are visited by the garbage collection if a mark and sweep algorithm is used? If an object is examined more than once count it
just once (i.e., we want the count of objects, not the count of object visits).
[Your answer should be in Arabic numerals with no other punctuation (e.g. 0 or 1000, not zero or 1,000 or 1.000).]