【问题标题】:Does R clear memory used by sequence after executionR是否在执行后清除序列使用的内存
【发布时间】:2020-02-28 22:34:03
【问题描述】:

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

【问题讨论】:

  • R 会将结果存储在变量.Last.value 中,因此在运行另一个命令之前不会释放seq(0,100000,0.01) 使用的内存
  • @DiceboyT 也是如此,即使运行命令将值存储在变量中,例如 foo <- 42
  • @JonathanRauscher 是的,但是内存地址会和foo一样
  • @DiceboyT 如果您将评论添加为答案,我很乐意将其标记为已接受的答案:)

标签: r memory seq


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2017-02-07
    • 1970-01-01
    • 2015-05-24
    • 1970-01-01
    • 1970-01-01
    • 2013-08-25
    • 2020-04-25
    • 1970-01-01
    • 2014-01-15
    相关资源
    最近更新 更多