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

Discussion 5 - Chris Gray

Discussion 5 - Chris Gray

Garbage collection is another way of handling memory allocation and deallocation. Whereas a language such as C requires the programmer to manually allocate memory as needed and free it when it is no longer used, garbage collection automates the process. The garbage collector will periodicly remove unused objects from memory.

Advantages:

Garbage collection is much easier on the programmer. It is quite common for the programmer to make an error in allocating memory or to forget to free it when finished. This is a serious problem in programs run for long periods of time as this loss of free memory or 'memory leak' can seriously impede performance. Garbage collection allows the programmer to focus on the design of the project and expect this finer detail to be handled for him. Many a Tech student was first introduced to the concept of allocating and freeing memory in C and many a project was marred by incorrect allocations or forgetting to free code.

Disadvantages:

Garbage collection is not free. When it is run it consumes CPU cycles and this can obviously be a problem on an already stressed computer. In these days of exceptionally powerful desktop computers and more efficient collection, this is less of a problem. In times past, some programs would actually pause to perform their garbage collection. In addition to this performance hit, some programmers do not like the loss of control.

How:

Generational - Heap is divided into generational sub-heaps. The youngest heaps are collected most often and after an object survives a few collections it is moved up a generation.

Reference count - Keeps a count of references to an object. Has the advantage of not interrupting but the major disadvantage of not handling two objects which reference each other.

Tracing - The most common one today. The collector traces out references by starting with root nodes. Encountered objects are marked in some way and at the end of the trace unmarked objects are garbage collected.

Generational is actually just a sub-type of tracing (or mark-and-sweep)

Links to this Page