Program 1:
library(pryr) for (x in 1:3) { print(c(address(x), refs(x))) }
Output, for example:
[1] "0x7a6a6c8" "1" [1] "0x7a6a6c8" "1" [1] "0x7a6a6c8" "1"
Program 2:
library(pryr) for (x in 1:3) { print(c(address(x), refs(x))) print(x) }
Output, for example:
[1] "0x7ae0298" "1" [1] 1 [1] "0x7ae88c8" "1" [1] 2 [1] "0x7af2668" "1" [1] 3
Obviously, the value of x changes in program 2, but why does the address change? Could this lead to a memory leak if there is a for loop that runs about 500,000,000 times, while gc is not called during the loop?
memory for-loop r pryr
Wipster
source share