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 - Steven Carr

Q. What is garbage collection? What are the advantages of using garbage collection? What are the disadvantages?

What is garbage collection?
Garbage collection is a service that recycles used memory so it can be used again. It finds objects that are no longer needed by the program, ones that don't have references to them, and frees the memory they occupy. Two different approaches to finding unused objects are reference counting and tracing. In reference counting, the virtual machine keeps track of how many objects have a reference to an object, removing it from memory when the count reaches 0. In tracing, the virtual machine graphs out references from root nodes, marking the objects that can be reached. Unmarked objects are deleted.

What are the advantages of using garbage collection?
Garbage collection removes the need for the programmer to free up memory manually. This can be incredibly difficult and time consuming, so it is a big help to the programmer. It also helps deal with heap fragmentation, preventing the program from running out of memory unnecessarily.

What are the disadvantages?
The main problem with garbage collection is that it adds overhead to the program. It takes CPU cycles for the virtual machine to keep track of which objects are still being used and to remove unused objects. It also reduces the control the programmer has less control over memory.

Links to this Page