View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Discussion 5 - Nazli Dokuzoglu

Nazli Dokuzoglu
Discussion 5

Garbage Collection

1) What is “Garbage Collection”?

Garbage collection is recycling an object that is no longer referenced by the program to make the space, used by the unreferenced object, available for the new object.
In Squeak, garbage collection is handled by virtual machine.

2) What are the advantages of garbage collection?

3) What are the disadvantages of garbage collection?

Garbage Collection Algorithms

4) Explain two garbage collection algorithms, Reference Counting and Mark-Sweep, briefly.

Reference Counting Algorithm
When an object is first created and a reference to it is assigned to a variable, the object's reference count is set to one. When any other variable is assigned a reference to that object, the object's count is incremented. When a reference to an object goes out of scope or is assigned a new value, the object's count is decremented. Any object with a reference count of zero can be garbage collected. When an object is garbage collected, any objects that it refers to have their reference counts decremented.
Mark-Sweep Algorithm

6) What is the problem with each algorithm? Give an example.
Reference Counting Algorithm cannot detect cycles (objects pointing to each other).
The two objects that are pointing to each other will never have a count equal to zero, so they will not be garbage collected but they may be unreachable by the root nodes of the program.
In Mark-Sweep Algorithm some of the objects need to be finalized before garbage collected so they require two garbage collection cycles. An example for this can be network sockets, they should be closed first and then garbage collected.

5) Which of the nodes need to be garbage collected according to the Mark-Sweep algorithm?
Uploaded Image: Figure1.JPG

C and G


Links to this Page