tracemem                package:base                R Documentation

_T_r_a_c_e _C_o_p_y_i_n_g _o_f _O_b_j_e_c_t_s

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

     This function marks an object so that a message is printed
     whenever the internal function 'duplicate' is called.   This
     happens when two objects share the same memory  and one of them is
     modified.  It is a major cause of hard-to-predict memory use in R.

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

     tracemem(x)
     untracemem(x)
     retracemem(x, previous = NULL)

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

       x: An R object, not a function or environment or 'NULL'.

previous: A value as returned by 'tracemem' or 'retracemem'.

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

     This functionality is optional, determined at compilation, because
     it makes R run a little more slowly even when no objects are being
     traced. 'tracemem' and 'untracemem' give errors when R is not
     compiled with memory profiling; 'retracemem' does not (so it can
     be left in code during development).

     When an object is traced any copying of the object by the C
     function 'duplicate' or by arithmetic or mathematical operations
     produces a message to standard output.  The message consists of
     the string 'tracemem', the identifying strings for the object
     being copied and the new object being created, and a stack trace
     showing where the duplication occurred.  'retracemem()' is used to
     indicate that a variable should be considered a copy of a previous
     variable (e.g. after subscripting).

     The messages can be turned off with 'tracingState'.

     It is not possible to trace functions, as this would conflict with
     'trace' and it is not useful to trace 'NULL', environments,
     promises, weak references, or external pointer objects, as these
     are not duplicated.

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

     A character string for identifying the object in the trace output
     (an address in hex enclosed in angle brackets), or 'NULL'
     (invisibly for 'untracemem'.

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

     'trace', 'Rprofmem'

     <URL: http://developer.r-project.org/memory-profiling.html>

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

     ## Not run: 
     a <- 1:10
     tracemem(a)
     ## b and a share memory
     b <- a
     b[1] <- 1
     untracemem(a)

     ## copying in lm
     d <- stats::rnorm(10)
     tracemem(d)
     lm(d ~ a+log(b))

     ## f is not a copy and is not traced
     f <- d[-1]
     f+1
     ## indicate that f should be traced as a copy of d
     retracemem(f, retracemem(d))
     f+1
     ## End(Not run)

