gc package:base R Documentation _G_a_r_b_a_g_e _C_o_l_l_e_c_t_i_o_n _D_e_s_c_r_i_p_t_i_o_n: A call of 'gc' causes a garbage collection to take place. 'gcinfo' sets a flag so that automatic collection is either silent ('verbose=FALSE') or prints memory usage statistics ('verbose=TRUE'). _U_s_a_g_e: gc(verbose = getOption("verbose"), reset=FALSE) gcinfo(verbose) _A_r_g_u_m_e_n_t_s: verbose: logical; if 'TRUE', the garbage collection prints statistics about cons cells and the space allocated for vectors. reset: logical; if 'TRUE' the values for maximum space used are reset to the current values. _D_e_t_a_i_l_s: A call of 'gc' causes a garbage collection to take place. This will also take 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. R allocates space for vectors in multiples of 8 bytes: hence the report of '"Vcells"', a relict of an earlier allocator (that used a vector heap). When 'gcinfo(TRUE)' is in force, messages are sent to the message connection at each garbage collection of the form 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 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). _V_a_l_u_e: 'gc' returns a matrix with rows '"Ncells"' (_cons cells_), usually 28 bytes each on 32-bit systems and 56 bytes on 64-bit systems, and '"Vcells"' (_vector cells_, 8 bytes each), and columns '"used"' and '"gc trigger"', each also interpreted in megabytes (rounded up to the next 0.1Mb). If maxima have been set for either '"Ncells"' or '"Vcells"', a fifth column is printed giving the current limits in Mb (with 'NA' denoting no limit). The final two columns show the maximum space used since the last call to 'gc(reset=TRUE)' (or since R started). 'gcinfo' returns the previous value of the flag. _S_e_e _A_l_s_o: The 'R Internals' manual. 'Memory' on R's memory management, and 'gctorture' if you are an R developer. 'reg.finalizer' for actions to happen at garbage collection. _E_x_a_m_p_l_e_s: 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)