reg.finalizer              package:base              R Documentation

_F_i_n_a_l_i_z_a_t_i_o_n _o_f _o_b_j_e_c_t_s

_D_e_s_c_r_i_p_t_i_o_n:

     Registers an R function to be called upon garbage collection of
     object.

_U_s_a_g_e:

       reg.finalizer(e, f)

_A_r_g_u_m_e_n_t_s:

       e: Object to finalize. Must be environment or external pointer.

       f: Function to call on finalization. Must accept a single
          argument, which will be the object to finalize.

_V_a_l_u_e:

     'NULL'.

_N_o_t_e:

     The purpose of this function is mainly to allow objects that refer
     to external items (a temporary file, say) to perform cleanup
     actions when they are no longer referenced from within R.  This
     only makes sense for objects that are never copied on assignment,
     hence the restriction to environments and external pointers.

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

     'gc' and 'Memory' for garbage collection and memory management.

_E_x_a_m_p_l_e_s:

     f <- function(e) print("cleaning....")
     g <- function(x){ e <- environment(); reg.finalizer(e,f) }
     g()
     invisible(gc()) # trigger cleanup

