0

I have a moderate size .xlsx file with the dimension of 40,000 rows and 15 columns. I loaded that data into R Workspace by using xlsx::loadWorkbook function. Before loading that data, my PC RAM size is 90 MB. After loading that data, my PC RAM size is 650 MB. Below is the code which I used to load the data.

library(xlsx)
file=\\file_path\\
wb <- xlsx::loadWorkbook(file)

Then I removed wb object from the R Workspace by using rm(wb). After I removed that file from Workspace, my PC RAM size din't change. It's still remains same as 650MB. I am very sure that, I don't have any other objects in my Workspace. Why it is happening? and What should I do to free up my PC RAM size?

DTYK
  • 1,098
  • 1
  • 8
  • 33
RSK
  • 751
  • 2
  • 7
  • 18
  • You might want to take a look at this thread about memory management: https://stackoverflow.com/questions/15561331/release-memory-in-r – DTYK Jun 21 '18 at 11:57
  • For a more memory efficient way of importing data, you could export the data to csv first. This is much quicker and less RAM hungry. – hannes101 Jun 21 '18 at 13:59
  • My objective is to add colors to the cells based on their numbers. That's why I am loading them in workbook format. – RSK Jun 22 '18 at 05:33

1 Answers1

0

I did some exploring on my own. You might want to try the following

memory.size()
gc()
memory.size()
rm(list=ls())
memory.size()
gc()
memory.size()

The function memory.size() reports the amount of memory currently in use. The function gc()causes a garbage collection to take place. After which, you can use memory.size() again to see how much memory has been freed up from garbage collection. The command rm(list=ls()) removes all objects from your global environment. After which, you can use memory.size() to see how much memory has been freed after removing all objects in your global environment.

At this point, there might be some more memory still in use, even though you have removed all objects from the global environment (which you have described). Do another garbage collection and check the memory. Your memory should have gone down (which was what I found). Hope this helps!

DTYK
  • 1,098
  • 1
  • 8
  • 33
  • I don't see significant improvement with the above functions. It just reduced single digit(`9 MB`) space. – RSK Jun 22 '18 at 05:32