Garbage collection: Difference between revisions

From Rosetta Code
Content added Content deleted
No edit summary
(Cleaned, the example removed (it was of non-GC))
Line 1: Line 1:
[[Category:Encyclopedia]]'''Garbage collection''' (often abbreviated as '''GC''') is a technique used for management of the life time of the object created [[run time|dynamically]], which scope is [[compile time|statically]] indeterminable. Sometimes called "automatic memory management". The object that are no longer in use by the program are said to be "collected," i.e. finalized and the memory allocated for the object is returned to the language environment.
[[Category:Encyclopedia]]'''Garbage collection''' (often abbreviated as '''GC''') is a technique used for management of the life cycle of the objects created [[run time|dynamically]], which scope is [[compile time|statically]] indeterminable. Sometimes GC is called "automatic memory management". Under GC the objects that are no longer in use by the program are said to be "collected." The object is finalized and then the memory allocated for it is returned to the language environment for further reuse. An object is considered not in use when there is no legal way to access it. In particular, when there are no other accessible objects [[reference|referencing]] it. Many GC algorithms differentiate in the way they determine absence of references.


Some [[programming language|programming languages]] (such as [[Java]], [[Tcl]], and [[Toka]]) have integrated GC support.
Some [[programming language|programming languages]] (such as [[Java]], [[Tcl]], and [[Toka]]) have an integrated GC support. Languages like [[Ada]] allow implementations with GC, but don't mandate it. Other languages (such as [[C]] and [[C++]]) do not have GC.


GC is frequently critiqued for:
An object is considered not in use when there is no legal way to access it. In particular, when there are no other accessible objects [[reference|referencing]] it. For instance (in a language with scope):
for i = 1 to 10
var x = i * i
print "x is in scope since it was declared in this for block"
end for
print "x is no longer in scope and its memory location should now be given back to the OS"


* unpredictable performance both in terms of time and space;
Some languages (such as [[C]] and [[C++]]) do not have garbage collection and the programmer must do it himself.
* distributed overhead for [[task|multi-tasking]] systems;
* difficulties in ensuring a proper finalization of collected objects;
* encouraging loose program design.

GC is a very vivid research area in computer science, focused on overwhelming the above mentioned drawbacks.

Revision as of 09:40, 26 August 2008

Garbage collection (often abbreviated as GC) is a technique used for management of the life cycle of the objects created dynamically, which scope is statically indeterminable. Sometimes GC is called "automatic memory management". Under GC the objects that are no longer in use by the program are said to be "collected." The object is finalized and then the memory allocated for it is returned to the language environment for further reuse. An object is considered not in use when there is no legal way to access it. In particular, when there are no other accessible objects referencing it. Many GC algorithms differentiate in the way they determine absence of references.

Some programming languages (such as Java, Tcl, and Toka) have an integrated GC support. Languages like Ada allow implementations with GC, but don't mandate it. Other languages (such as C and C++) do not have GC.

GC is frequently critiqued for:

  • unpredictable performance both in terms of time and space;
  • distributed overhead for multi-tasking systems;
  • difficulties in ensuring a proper finalization of collected objects;
  • encouraging loose program design.

GC is a very vivid research area in computer science, focused on overwhelming the above mentioned drawbacks.