EVOLUTION-MANAGER
Edit File: gc.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Garbage Collection</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for gc {base}"><tr><td>gc {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Garbage Collection</h2> <h3>Description</h3> <p>A call of <code>gc</code> causes a garbage collection to take place. <code>gcinfo</code> sets a flag so that automatic collection is either silent (<code>verbose = FALSE</code>) or prints memory usage statistics (<code>verbose = TRUE</code>). </p> <h3>Usage</h3> <pre> gc(verbose = getOption("verbose"), reset = FALSE, full = TRUE) gcinfo(verbose) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>verbose</code></td> <td> <p>logical; if <code>TRUE</code>, the garbage collection prints statistics about cons cells and the space allocated for vectors.</p> </td></tr> <tr valign="top"><td><code>reset</code></td> <td> <p>logical; if <code>TRUE</code> the values for maximum space used are reset to the current values.</p> </td></tr> <tr valign="top"><td><code>full</code></td> <td> <p>logical; if <code>TRUE</code> a full collection is performed; otherwise only more recently allocated objects may be collected.</p> </td></tr> </table> <h3>Details</h3> <p>A call of <code>gc</code> causes a garbage collection to take place. This will also take place automatically without user intervention, and the primary purpose of calling <code>gc</code> is for the report on memory usage. For an accurate report <code>full = TRUE</code> should be used. </p> <p>It can be useful to call <code>gc</code> after a large object has been removed, as this may prompt <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> to return memory to the operating system. </p> <p><span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> allocates space for vectors in multiples of 8 bytes: hence the report of <code>"Vcells"</code>, a relict of an earlier allocator (that used a vector heap). </p> <p>When <code>gcinfo(TRUE)</code> is in force, messages are sent to the message connection at each garbage collection of the form </p> <pre> Garbage collection 12 = 10+0+2 (level 0) ... 6.4 Mbytes of cons cells used (58%) 2.0 Mbytes of vectors used (32%) </pre> <p>Here the last two lines give the current memory usage rounded up to the next 0.1Mb and as a percentage of the current trigger value. The first line gives a breakdown of the number of garbage collections at various levels (for an explanation see the ‘R Internals’ manual). </p> <h3>Value</h3> <p><code>gc</code> returns a matrix with rows <code>"Ncells"</code> (<em>cons cells</em>), usually 28 bytes each on 32-bit systems and 56 bytes on 64-bit systems, and <code>"Vcells"</code> (<em>vector cells</em>, 8 bytes each), and columns <code>"used"</code> and <code>"gc trigger"</code>, each also interpreted in megabytes (rounded up to the next 0.1Mb). </p> <p>If maxima have been set for either <code>"Ncells"</code> or <code>"Vcells"</code>, a fifth column is printed giving the current limits in Mb (with <code>NA</code> denoting no limit). </p> <p>The final two columns show the maximum space used since the last call to <code>gc(reset = TRUE)</code> (or since <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> started). </p> <p><code>gcinfo</code> returns the previous value of the flag. </p> <h3>See Also</h3> <p>The ‘R Internals’ manual. </p> <p><code><a href="Memory.html">Memory</a></code> on <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span>'s memory management, and <code><a href="gctorture.html">gctorture</a></code> if you are an <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> developer. </p> <p><code><a href="reg.finalizer.html">reg.finalizer</a></code> for actions to happen at garbage collection. </p> <h3>Examples</h3> <pre> gc() #- do it now gcinfo(TRUE) #-- in the future, show when R does it x <- integer(100000); for(i in 1:18) x <- c(x, i) gcinfo(verbose = FALSE) #-- don't show it anymore gc(TRUE) gc(reset = TRUE) </pre> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>