Beginning with version 1.4.1600, the RStudio IDE includes a small memory usage widget in the Environment pane.
This widget helps you track the amount of memory your R session is using.
The pie chart shows the total system memory usage; that is, if your system has 8GB of RAM and 4GB is currently in use, it will show at 50%.
The number next to the chart (203 MiB in this example) shows the memory usage of the R session. It is roughly the sum of the size of all of the R objects in the global environment, plus libraries and packages that have been loaded and internal R and RStudio overhead.
Click the triangle drop-down and choose "Memory Usage Report" to see a breakdown of your memory usage in more detail.
If your memory usage starts to approach your memory limit, then the indicator will turn from green to yellow, from yellow to orange, and eventually to red when you run out of memory.
Frequently Asked Questions
Why doesn't memory usage drop when I remove objects?
R is a garbage-collected language, which means that memory is not freed immediately when data is removed; it is only freed when R performs its occasional check to see if the data is still being referenced.
You can force R to perform this check, and free the memory right away, by running the gc() command in R or going to Tools -> Memory -> Free Unused R Memory.
Read more about Garbage Collection in R.
Can RStudio trigger a garbage collection for me when I am near the memory limit?
No, having RStudio meddle with R's internal memory accounting would cause instability. You can configure R's memory manager to collect garbage more aggressively and frequently if you need this sort of behavior. Read Memory Management in R for more details.
How often is the memory usage indicator updated?
Every 10 seconds by default. You can change this using the Command Palette.
Setting it to 0 will cause RStudio to stop performing periodic checks entirely, though the numbers will still be updated when you use R.
Is the memory used by background jobs or subprocesses included?
Only the memory used by the main R session is used to compute the session's memory usage. However, background jobs (and all other tasks on the system) contribute to system memory usage, which is accounted for in the pie chart displaying overall usage.
Why is the memory indicator greyed out/disabled?
On RStudio Workbench (previously RStudio Server Pro), your R session can enter a "suspended" state after an idle period defined by your administrator. In this state, your session is technically not using any memory at all. If your session is suspended, the memory indicator will turn grey and display the last known memory usage of the session.
In the above example the session was using 133 mebibytes of memory when it was suspended. When you interact with the IDE again, the session will resume, data will be read back into memory, and the memory indicator will light up again.
Where do these numbers come from?
RStudio uses system APIs to derive memory usage statistics on MacOS and Windows. On Linux, it will use cgroups if it detects cgroup limits, and /proc/meminfo if it does not.
This means that if you're running your R session in a Linux container, you will see limits and usage with respect to the container, not the host operating system, presuming of course that your container system is using cgroups for enforcement.
What units are used? What does MiB mean?
The memory usage indicator uses the standard units kebibyte (KiB), mebibyte (MiB), etc. These terms, while they may be slightly less familiar to some readers, refer unambiguously to the powers-of-two system (i.e. 1 KiB = 1,024 bytes, 1 MiB = 1,048,576 bytes), whereas units like kilobyte (KB) in practice could refer to either 1,000 or 1,024 bytes.
This is distracting! It changes all the time. How can I turn it off?
Go to Tools -> Memory and uncheck Show Current Memory Usage.