[R] gc() and gc trigger

Thomas Lumley tlumley at u.washington.edu
Fri Jun 10 19:41:15 CEST 2005


On Fri, 10 Jun 2005, Pavel Khomski wrote:

> hello,
>
> the question concerning to the memory used and g.c. after having removed
> objects.  What is wrong?

Nothing is wrong.

> bevor
> -------
>
> > gc()
>                   used   (Mb)     gc trigger       (Mb)     max used      (Mb)
> Ncells   313142     8.4         1801024         48.1       1835812  49.1
> Vcells    809238     6.2     142909728   1090.4   178426948   1361.3
>

>
> >  for (i in 1:30) gc()
> >  gc()
>                      used    (Mb)     gc trigger      (Mb)      max used      (Mb)
> Ncells     313149        8.4       1152655       30.8          1835812    49.1
> Vcells      809261        6.2       3218039       19.7     178426948  1361.3
>

The gc trigger level is the memory use at which gc() will be triggered. It 
goes down as R releases memory back to the operating system.  The amount 
used doesn't change because you aren't changing the amount used.

The max used doesn't change because, as the help says, it is the maximum 
usage since the last call to gc(reset=TRUE).


> > object.size(mget(ls(all=T),envir=.GlobalEnv)) / 1024^2
> [1] 9.829926

I'm not sure what this is supposed to prove.

>
> N.B.!!! the "max used "  is not put back
>
> > q()
>
> after having restarted R-prozess
> -------------------------------------
>
> > gc()
>                   used    (Mb)      gc trigger   (Mb)     max used (Mb)
> Ncells  302497        8.1           467875    12.5          350000  9.4
> Vcells   785346        6.0         1193335      9.2   923612        7.1
>

So now you start off with 14.1 Mb used.  The max used column shows that 
sometime during startup R was using more memory, and the gc trigger shows 
that garbage collection will happen when you get above 12.5 Mb Ncells or
9.2 Mb Vcells.


 	-thomas




More information about the R-help mailing list