Describe Garbage Collection

Go down

Describe Garbage Collection Empty Describe Garbage Collection

Post  Admin on Fri Aug 26, 2011 12:50 pm

Garbage collection is the process by which a program automatically finds and reclaims memory that is no longer used or no longer accessible by an application. This reclamation occurs whithout programmer assistance. C#, Java, Perl are examples of languages with garbage-collection facilitites.

Garbage collection provides several advantages over having a programmer explicitly deallocate memory. It eliminates bugs due to dangling pointers and memory leaks. It also promotes greate simplicity in program and interface design because the complicated mechanisms traditionally used to ensure that memory is properly freed are unnecessary. In addition, because programmers donot have to worry about memory deallocation, program development proceeds at a more rapid pace.

Garbage colleciton is not without its disadvantages. Garbage collected programs often run more slowly because of the overhead needed for the system to determine when to deallocate and reclaim memory no longer needed.

One method of garbage collection is to use REFERENCE COUNTING. This involves tracking how may variables reference an object. Initially, there will be one reference to a piece of memory. The reference count will increase if the variable referencing it is copied. When a variable referencing an object changes value or goes out of scope, the object's reference count is decremented. If a reference count ever goes to 0, the memory associated with the object is freed. If no one is keeping a reference to the object, then the object is no longer needed.

A second method of garbage collection is known as MARK AND SWEEP. (Assume circular references in a linked list). In the first pass, the memory manager will mark all objects that can be accessed by any thread in the program. In the second pass, all unmarked objects are deallocated, or swept away.


Posts : 131
Join date : 2011-08-16

View user profile

Back to top Go down

Back to top

- Similar topics

Permissions in this forum:
You cannot reply to topics in this forum