R是否在执行后清除序列使用的内存

Does R clear memory used by sequence after execution

正如标题所示,我想知道 seq 使用的内存在执行后是否再次可用,例如 seq(0,100000,0.01)

R 会将结果存储在变量 .Last.value 中,因此 seq(0,100000,0.01) 使用的内存不会被释放,直到您 运行 另一个命令:

initial_memory <- sum(gc()[, "used"])

seq(0,100000,0.01)

# memory difference after running command
new_memory <- sum(gc()[, "used"])
new_memory - initial_memory
#> [1] 1e+07

# if we run again, we see memory return close to original
new_memory <- sum(gc()[, "used"])
new_memory - initial_memory
#> [1] -16