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"))
     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 vector heap.

_D_e_t_a_i_l_s:

     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.

_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).

     'gcinfo' returns the previous value of the flag.

_S_e_e _A_l_s_o:

     'Memory' on R's memory management, and 'gctorture' if you are an R
     hacker. 'reg.finalizer' for actions to happen upon 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)

