※ 引述《litchi (狂恋大屁股)》之铭言:
: However, data.frame and matrix are different in my experiment~
: (under my Debian machine with CPU p3-667 and memory 160MB)
: %MEM
: 9711 9 0 108m 81m 16m S 0.0 52.3 0:18.70 R.bin
: 9716 9 0 47748 46m 2260 S 0.0 29.7 0:04.02 R.bin
: Process 9711 allocates a data.frame with size 2000x2000, and process
: 9716 allocates a matrix with the same size.
: The statements execute in process 9711 is below
: > m <- as.data.frame(matrix(0, 2000, 2000))
: > gc()
: The statements execute in process 9716 is below
: > m <- matrix(0, 2000, 2000)
: > gc()
^^^^
I think executing gc() might not be the necessary step. I just want to be
more careful about the experiment.
See the excerpt from the man page of gc().
========================================================================
Details:
A call of 'gc' causes a garbage collection to take place. This
takes place automatically without user intervention, and the
primary purpose of calling 'gc' is for the report on memory usage.
However, it can be useful to call 'gc' after a large object has
been removed, as this may prompt R to return memory to the
operating system.
========================================================================
I don't remove any object in my test. Therefore, gc() shouldn't return
much memory to the OS, and the garbage would not affect the experiment.