0

Need your help in understanding memory usage in R. As per this link http://adv-r.had.co.nz/memory.html#gc

It says " object_size() tells you the size of a single object, pryr::mem_used() tells you the total size of all objects in memory:"

enter image description here

But I did an experiment to make sure this works as mentioned. But I see some differences.

> new_asd <- iris %>% group_by(Species) %>% summarise(Sepal.Length = sum(Sepal.Length))
> new_asd_1 <- iris %>% group_by(Species) %>% summarise(Sepal.Length = sum(Sepal.Length))
> mem_used()
134 MB
> object_size(new_asd, new_asd_1)
2,272 B

Please see above, the total memory and objects size of all the objects are not same. I also created another object

> new_asd_2 <- iris %>% group_by(Species) %>% summarise(Sepal.Length = sum(Sepal.Length))
> object_size(new_asd, new_asd_1, new_asd_2)
2,960 B
> mem_used()
134 MB

Still the mem_used is same 134MB. Not sure why???

manu p
  • 952
  • 4
  • 10
  • Rounding? If you're already using 134MB, is another <3kB relevant in most situations? – Limey Jan 27 '22 at 16:07
  • Total memory used will include various other objects such as hidden objects and open files. It will never be zero and never be just the sum of objects listed in your environment. You also get some memory leakage meaning that long-running sessions keep adding to memory with time. Worth restarting R regularly if you run into issues with too much `mem_used()` – c_j_fairfield Jan 27 '22 at 16:07
  • There is a more detailed question and answer about memory here: https://stackoverflow.com/questions/53333858/how-to-clean-up-r-memory-without-the-need-to-restart-r-session – c_j_fairfield Jan 27 '22 at 16:10
  • Thanks all :).. – manu p Jan 27 '22 at 16:10

0 Answers0