Manage Heap Size
TERR
does not have built-in memory allocation size limits, except those imposed by
the operating system (for example, the 2 gigabyte limit on 32-bit Windows).
However, to prevent possible negative effects on the performance of other
running applications, it is possible to set a limit on the total memory
allocation by calling the
memory.limit
function.
The initial value of the
memory.limit
function is zero (meaning no limit), and it
can be set to an integer for the number of megabytes. This limit might keep
attempts at simultaneous large memory allocations (for example, those of large
matrices) from succeeding.
The following example demonstrates increasing the total allocation limit to 2 gigabytes after hitting a 1 gigabyte limit with two large object allocations.
memory.limit(1024) #set limit to 1GB
[1] 0
m <- 10000
n <- 10000
A <- matrix (runif (m*n),m,n)
# ~760 MegaByte - success
B <- matrix (runif (m*n),m,n)
# ~760 MegaByte more - failure due to initial 1GB limit
Error: out of memory
memory.limit(2*1024) # increase the limit to 2 GB
[1] 1024
memory.limit()
[1] 2048
B <- matrix (runif (m*n),m,n)
# ~760 MegaByte more - success after the limit increase