Garbage collection: Difference between revisions

From Rosetta Code
Content added Content deleted
(New page: Category:Encyclopedia'''Garbage collection''' (sometimes called "automatic memory management") is a feature of some programming languages (such as Java, [[...)
 
m (Corrected case)
Line 1: Line 1:
[[Category:Encyclopedia]]'''Garbage collection''' (sometimes called "automatic memory management") is a feature of some [[programming language|programming languages]] (such as [[Java]], [[tcl]], and [[Toka]]) which manages memory allocation so that memory locations that are no longer in use by the program are "given back" to the [[OS|operating system]].
[[Category:Encyclopedia]]'''Garbage collection''' (sometimes called "automatic memory management") is a feature of some [[programming language|programming languages]] (such as [[Java]], [[Tcl]], and [[Toka]]) which manages memory allocation so that memory locations that are no longer in use by the program are "given back" to the [[OS|operating system]].


A memory location is no longer in use when there are no [[reference|references]] to it in use anymore. For instance (in a language with scope):
A memory location is no longer in use when there are no [[reference|references]] to it in use anymore. For instance (in a language with scope):

Revision as of 15:26, 12 March 2008

Garbage collection (sometimes called "automatic memory management") is a feature of some programming languages (such as Java, Tcl, and Toka) which manages memory allocation so that memory locations that are no longer in use by the program are "given back" to the operating system.

A memory location is no longer in use when there are no references to it in use anymore. 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"

Some languages (such as C and C++) do not have garbage collection and the programmer must do it himself.