R中的内存使用情况 [英] Memory Usage in R

查看:265
本文介绍了R中的内存使用情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建大对象并用完RAM后,我将尝试使用以下方法在当前环境中删除对象

After creating large objects and running out of RAM, I will try and delete the objects in my current environment using

rm(list=ls())

当我检查我的RAM使用情况时,什么都没有改变.即使在调用gc()之后,也没有任何改变.我只能通过退出R来补充RAM.

When I check my RAM usage, nothing has changed. Even after calling gc() nothing has changed. I can only replenish my RAM by quitting R.

有人对处理R中内存密集型对象有建议吗?

Anybody have advice for dealing with memory-intensive objects within R?

推荐答案

已删除对象的内存不会立即释放. R使用一种称为垃圾收集"的技术来回收已删除对象的内存.它会周期性地遍历可访问对象的列表(基本上是具有名称但尚未删除并且因此可以由用户访问的对象),并对其进行标记"以进行保留.垃圾收集扫描后,所有未标记对象的内存将返回操作系统.

Memory for deleted objects is not released immediately. R uses a technique called "garbage collection" to reclaim memory for deleted objects. Periodically, it cycles through the list of accessible objects (basically, those that have names and have not been deleted and can therefore be accessed by the user), and "tags" them for retention. The memory for any untagged objects is returned to the operating system after the garbage-collection sweep.

垃圾收集自动发生,您对此过程没有任何直接控制.但是您可以通过从命令行调用命令gc()来强制进行扫描.

Garbage collection happens automatically, and you don't have any direct control over this process. But you can force a sweep by calling the command gc() from the command line.

即使那样,在某些操作系统上,垃圾回收也可能无法回收内存(如操作系统所报告).例如,较旧版本的Windows可能会增加R,但不会减少R的内存占用.垃圾回收只会在将来为新对象腾出空间,而不会减少R的内存使用.

Even then, on some operating systems garbage collection might not reclaim memory (as reported by the OS). Older versions of Windows, for example, could increase but not decrease the memory footprint of R. Garbage collection would only make space for new objects in the future, but would not reduce the memory use of R.

这篇关于R中的内存使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆