Class 19: Garbage Collection

Slides

Display version (pdf).

Downloads

Supplemental Reading

IBM Java Compiler explanation of garbage collection.

Homework

Exercises

The following exercises are due next Monday, November 21.

Consider the following SPL code:

new f := lambda a {
  new g := lambda b { ret := b + b/2; };
  new h := lambda c {
    new x := a*c;
    ret := lambda d { ret := g(d) < x; };
  };
  ret := h;
};
new foo := f(3)(4);
write foo(8);
  1. Draw the frames and closures that are created in executing the program. Label each frame with a number. (Hint: there should be five frames total.)
  2. For each frame label, indicate what the reference count for that frame would be at the end of the program execution. Circle the labels for which frames would be de-allocated if we used reference counting for automatic garbage collection.
  3. For each frame label, indicate whether that frame would be marked or not after a "mark" operation starting with the global frame as the "root set". Circle the labels for which frames would be de-allocated if we used mark-and-sweep for automatic garbage collection.