Beginning in RStudio 1.4.1600, RStudio 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.
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.
This is distracting! It changes all the time. How can I turn it off?
Go to Tools -> Memory and uncheck Show Current Memory Usage.