[R-pkg-devel] Unused data is silently kept in the environment of a function

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Fri Jul 8 17:10:20 CEST 2022


On 08/07/2022 11:01 a.m., Duncan Murdoch wrote:
  ... lots deleted

> So you'll end up with this chain of environments:
> 
>     environment(function(z) z / cofactor) is the evaluation environment
> of function(cofactor) function(z) z / cofactor;
> 
>     its parent is the evaluation environment of proc_0, containing dat;
> 
>     its parent is environment(proc_0), which is the global environment.
> 
> The global environment isn't captured, but the others are, so you save a
> copy of dat every time you call proc_0.

This may be misleading.  The reference to the global environment will be 
there; what I meant is that there's no extra copy of the global 
environment.  If we didn't have the references in the chain above, the 
evaluation environments would all have been garbage collected after 
proc_0 finished, but because we still have references to them, they are 
"captured", so we keep a copy until those references go away when the 
result of the proc_0 call is deleted.

Duncan Murdoch



More information about the R-package-devel mailing list