mem: See what is using up memory but just for 1 environment

View source: R/mem.R

memR Documentation

See what is using up memory but just for 1 environment

Description

See a list of the largest objects in memory, and how much RAM they are using up Uses object.size() to return info on memory consumption for largest n objects

Usage

mem(n = 10, env = .GlobalEnv)

Arguments

n

Numeric, default is 10. How many objects to show (e.g., top 10)

env

The environment to check, defaulting to .GlobalEnv but could be something like env = as.environment(3) or 3

Value

prints a list of objects and their sizes

Examples

  ## Not run: 
mem()
mem(15)
mem(env = 2)

# draw bar plot
y = mem()
barplot(y,
        main="Memory usage by object", ylab="Bytes", xlab="Variable name",
        col=heat.colors(length(y)))

# draw pie chart again
pie(mem(), main = "Memory usage by object")


################################## #
# memory.size() and memory.limit() and object.sizes() comparison:
################################## #

memory.size() to print aggregate memory usage statistics


print(paste('R is using', memory.size(), 'MB out of limit', memory.limit(), 'MB'))

# object.sizes() to see memory total used by objects:

# NOTE: THIS DOES NOT MATCH TOTAL GIVEN BY memory.size();
#  it is only about half as much in the case I tried:
sum(as.numeric(object.sizes()))
# same, in MEGABYTES:
unclass(sum(as.numeric(object.sizes())))/1e6
# print to console in table format
object.sizes()
#	see a list of the top few variables:
head(cbind(object.sizes()))

## End(Not run)


ejanalysis/analyze.stuff documentation built on April 2, 2024, 10:10 a.m.