Garbage collection

From Rosetta Code
Revision as of 23:45, 11 March 2008 by rosettacode>Mwn3d (New page: Category:Encyclopedia'''Garbage collection''' (sometimes called "automatic memory management") is a feature of some programming languages (such as Java, [[...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.