Can someone explain why obj_size
behaves differently than base object.size
?
library(lobstr)
x <- runif(1e6)
y <- list(c(x), x)
z <- list(x, x)
all.equal(y, z)
#> [1] TRUE
object.size(y)
#> 16000160 bytes
object.size(z)
#> 16000160 bytes
obj_size(y)
#> 16,000,160 B
obj_size(z)
#> 8,000,112 B
Created on 2018-11-08 by the reprex package (v0.2.1)
In the docs I see:
Compared to
object.size()
,obj_size()
:
- Accounts for all types of shared values, not just strings in the global string pool.
- Includes the size of environments (up to
env
)- Accurately measures the size of ALTREP objects.
But I'm not sure which one of those points might be highlighting the difference between the two.