Report the Space Allocated for an Object
Provides an estimate of the memory that is being used to store an R object.
1 2 3 4 5 6
an R object.
logical, indicating whether or not the result should be printed with surrounding quotes.
the units to be used in printing the size. Allowed
arguments to be passed to or from other methods.
Exactly which parts of the memory allocation should be attributed to which object is not clear-cut. This function merely provides a rough indication: it should be reasonably accurate for atomic vectors, but does not detect if elements of a list are shared, for example. (Sharing amongst elements of a character vector is taken into account, but not that between character vectors in a single object.)
The calculation is of the size of the object, and excludes the space needed to store its name in the symbol table.
Associated space (e.g., the environment of a function and what the
pointer in a
EXTPTRSXP points to) is not included in the
Object sizes are larger on 64-bit builds than 32-bit ones, but will very likely be the same on different platforms with the same word length and pointer size.
units = "auto" in the
The IEC standard for binary byte size units uses notation
etc. Note that our uses of
Mb, etc, also mean
1024 (and not of
1000) and hence the numbers
KiB are all the same - contrary
to SI standard but according to widespread tradition.
An object of class
"object_size" with a length-one double value,
an estimate of the memory allocation attributable to the object in bytes.
Memory-limits for the design limitations on object size.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
object.size(letters) object.size(ls) format(object.size(library), units = "auto") sl <- object.size(rep(letters, 1000)) (fsl <- sapply(c("Kb", "KB", "KiB"), function(u) format(sl, units = u))) stopifnot(identical( ## assert that all three are the same : unique(substr(as.vector(fsl), 1,5)), format(round(as.vector(sl)/1024, 1)))) ## find the 10 largest objects in the base package z <- sapply(ls("package:base"), function(x) object.size(get(x, envir = baseenv()))) as.matrix(rev(sort(z))[1:10])