[R] gc() vs memory.profile()
Ross Boylan
ross at biostat.ucsf.edu
Fri Dec 27 20:49:50 CET 2013
I am trying to understand why a function causes my memory use to
explode. While doing that I noticed that my memory use as reported by
gc() is growing, but the results of memory.profile() are almost
unchanged (the count for raw grew by 3). How can the two functions
produce different results, and what does it mean?
> system.time(r <- Reduce(addResults, bigr[1:10]))
user system elapsed
3.437 0.000 3.444
> gc()
used (Mb) gc trigger (Mb) max used (Mb)
Ncells 2994756 160.0 4418719 236.0 3587436 191.6
Vcells 797226672 6082.4 2470056017 18845.1 7340162895 56001.0
> memory.profile()
NULL symbol pairlist closure environment promise
1 13324 1193588 34602 3000 9754
language special builtin char logical integer
305689 44 637 52237 53954 141713
double complex character ... any list
548076 38 426187 39 0 116692
expression bytecode externalptr weakref raw S4
1 65604 4195 708 735 23935
> system.time(r <- Reduce(addResults, bigr[1:20]))
user system elapsed
8.432 0.164 10.315 # suspiciously higher than 2* time for 10
> gc()
used (Mb) gc trigger (Mb) max used (Mb)
Ncells 2994759 160.0 4418719 236.0 3587436 191.6
!Vcells 828653314 6322.2 2470056017 18845.1 7340162895 56001.0
> memory.profile()
NULL symbol pairlist closure environment promise
1 13324 1193588 34602 3000 9754
language special builtin char logical integer
305689 44 637 52237 53954 141713
double complex character ... any list
548076 38 426187 39 0 116692
expression bytecode externalptr weakref raw S4
1 65604 4195 708 738 23935
# by eye, the only change is raw, from 735 to 738.
R 3.0.1 running on Debian GNU/Linux squeeze.
Ross Boylan
More information about the R-help
mailing list