[ RDocumentation ](/)

Moon  [ ](https://github.com/datacamp/rdocumentation-2.0) [ Learn R
](https://www.datacamp.com/learn/r)

Search all packages and functions

[ base  (version  3.6.2  ) ](/packages/base/versions/3.6.2)

#  Memory: Memory Available for Data Storage

##  Description

How  R  manages its workspace.

##  Arguments

##  Details

R  has a variable-sized workspace. There are (rarely-used) command-line
options to control its minimum size, but no longer any to control the maximum
size.

On Windows the  \--max-mem-size  option (or environment variable `
R_MAX_MEM_SIZE ` ) sets the maximum (virtual) memory allocation: it has a
minimum allowed value of 32M. This is intended to catch attempts to allocate
excessive amounts of memory which may cause other processes to run out of
resources. See also ` [ memory.limit
](/link/memory.limit?package=base&version=3.6.2) ` .

R  maintains separate areas for fixed and variable sized objects. The first of
these is allocated as an array of _cons cells_ (Lisp programmers will know
what they are, others may think of them as the building blocks of the language
itself, parse trees, etc.), and the second are thrown on a _heap_ of ‘Vcells’
of 8 bytes each. Each cons cell occupies 28 bytes on a 32-bit build of  R  ,
(usually) 56 bytes on a 64-bit build.

The default values are (currently) an initial setting of 350k cons cells and
6Mb of vector heap. Note that the areas are not actually allocated initially:
rather these values are the sizes for triggering garbage collection. These
values can be set by the command line options  \--min-nsize  and  \--min-vsize
(or if they are not used, the environment variables ` R_NSIZE ` and ` R_VSIZE
` ) when  R  is started. Thereafter  R  will grow or shrink the areas
depending on usage, never decreasing below the initial values. The maximal
vector heap size can be set with the environment variable ` R_MAX_VSIZE ` .

How much time  R  spends in the garbage collector will depend on these initial
settings and on the trade-off the memory manager makes, when memory fills up,
between collecting garbage to free up unused memory and growing these areas.
The strategy used for growth can be specified by setting the environment
variable ` R_GC_MEM_GROW ` to an integer value between 0 and 3. This variable
is read at start-up. Higher values grow the heap more aggressively, thus
reducing garbage collection time but using more memory.

You can find out the current memory consumption (the heap and cons cells used
as numbers and megabytes) by typing ` [ gc
](/link/gc?package=base&version=3.6.2) () ` at the  R  prompt. Note that
following ` [ gcinfo ](/link/gcinfo?package=base&version=3.6.2) (TRUE) ` ,
automatic garbage collection always prints memory use statistics.

The command-line option  \--max-ppsize  controls the maximum size of the
pointer protection stack. This defaults to 50000, but can be increased to
allow deep recursion or large and complicated calculations to be done. _Note_
that parts of the garbage collection process goes through the full reserved
pointer protection stack and hence becomes slower when the size is increased.
Currently the maximum value accepted is 500000.

##  See Also

_An Introduction to R_ for more command-line options.

` [ Memory-limits ](/link/Memory-limits?package=base&version=3.6.2) ` for the
design limitations.

` [ gc ](/link/gc?package=base&version=3.6.2) ` for information on the garbage
collector and total memory usage, ` [ object.size
](/link/object.size?package=base&version=3.6.2) (a) ` for the (approximate)
size of  R  object ` a ` . ` [ memory.profile
](/link/memory.profile?package=base&version=3.6.2) ` for profiling the usage
of cons cells.

` [ memory.size ](/link/memory.size?package=base&version=3.6.2) ` to monitor
total memory usage, ` [ memory.limit
](/link/memory.limit?package=base&version=3.6.2) ` for the current limit.

Powered by  [ DataCamp ](https://www.datacamp.com/)