Rev 79507 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/base/man/gc.Rd% Part of the R package, https://www.R-project.org% Copyright 1995-2020 R Core Team% Distributed under GPL 2 or later\name{gc}\title{Garbage Collection}\usage{gc(verbose = getOption("verbose"), reset = FALSE, full = TRUE)gcinfo(verbose)}\alias{gc}\alias{gcinfo}\arguments{\item{verbose}{logical; if \code{TRUE}, the garbage collection printsstatistics about cons cells and the space allocated for vectors.}\item{reset}{logical; if \code{TRUE} the values for maximum space usedare reset to the current values.}\item{full}{logical; if \code{TRUE} a full collection is performed;otherwise only more recently allocated objects may be collected.}}\description{A call of \code{gc} causes a garbage collection to take place.\code{gcinfo} sets a flag so thatautomatic collection is either silent (\code{verbose = FALSE}) orprints memory usage statistics (\code{verbose = TRUE}).}\details{A call of \code{gc} causes a garbage collection to take place.This will also take place automatically without user intervention, and theprimary purpose of calling \code{gc} is for the report on memoryusage. For an accurate report \code{full = TRUE} should be used.It can be useful to call \code{gc} after a large objecthas been removed, as this may prompt \R to return memory to theoperating system.\R allocates space for vectors in multiples of 8 bytes: hence thereport of \code{"Vcells"}, a relic of an earlier allocator (that useda vector heap).When \code{gcinfo(TRUE)} is in force, messages are sent to the messageconnection at each garbage collection of the form\preformatted{ Garbage collection 12 = 10+0+2 (level 0) ...6.4 Mbytes of cons cells used (58\%)2.0 Mbytes of vectors used (32\%)}Here the last two lines give the current memory usage rounded up tothe next 0.1Mb and as a percentage of the current trigger value.The first line gives a breakdown of the number of garbage collectionsat various levels (for an explanation see the \sQuote{R Internals} manual).}\value{\code{gc} returns a matrix with rows \code{"Ncells"} (\emph{conscells}), usually 28 bytes each on 32-bit systems and 56 bytes on64-bit systems, and \code{"Vcells"} (\emph{vector cells}, 8 byteseach), and columns \code{"used"} and \code{"gc trigger"},each also interpreted in megabytes (rounded up to the next 0.1Mb).If maxima have been set for either \code{"Ncells"} or \code{"Vcells"},a fifth column is printed giving the current limits in Mb (with\code{NA} denoting no limit).The final two columns show the maximum space used since the last callto \code{gc(reset = TRUE)} (or since \R started).\code{gcinfo} returns the previous value of the flag.}\seealso{The \sQuote{R Internals} manual.\code{\link{Memory}} on \R's memory management,and \code{\link{gctorture}} if you are an \R developer.\code{\link{gc.time}()} reports \emph{time} used for garbage collection.\code{\link{reg.finalizer}} for actions to happen at garbagecollection.}\examples{\donttest{gc() #- do it nowgcinfo(TRUE) #-- in the future, show when R does it## vvvvv use larger to *show* somethingx <- integer(100000); for(i in 1:18) x <- c(x, i)gcinfo(verbose = FALSE) #-- don't show it anymoregc(TRUE)gc(reset = TRUE)}}\keyword{environment}