1

I use R (version 3.0.2) on a Ubuntu 64bit (14.04) and the package read.xlsx to read several xlsx sheets. I do it like this:

options(java.parameters = "-Xmx4g" )
require(xlsx)
d1 = read.xlsx2(file, sheetName=sheet.1)
d2 = read.xlsx2(file, sheetName=sheet.2)
d3 = read.xlsx2(file, sheetName=sheet.3)

This works principally, but R need more ad more memory and when it starts swapping it doesn't terminate in a appropriate time. I think the problem is that the memory used to read the xlsx files is not freed after the function terminated, because even if I remove all data (remove(d1), ...) the memory is still occupied. I tried to find any old objects used by read.xlsx using ls() but there are no temporary objects...

A solution which works is to read files until the memory is full. Then save the workspace, close R, reopen R and load the saved workspace. But this is certainly not the best solution! Hence, the actual question: how can I force read.xlsx to free the memory (and kill subprocesses) after it finished?

MichaelChirico
  • 33,841
  • 14
  • 113
  • 198
Jonas
  • 1,639
  • 1
  • 18
  • 29
  • 2
    Try calling garbage collector `gc()` and see if that helps. It's difficult to say so far if that's a leak. If you're curious, you may try doing something like described [here](http://stackoverflow.com/questions/23696391/memory-leak-when-using-package-xml-on-windows) to investigate the issue. If your guess is correct, that'll be enough for a bug report. – tonytonov May 20 '14 at 11:16
  • Please post your `R` version and OS version as well. Can you explain why you need to set the java parameter? – Carl Witthoft May 20 '14 at 11:25
  • I added R and OS versions. The java parameter has to be set to prevent outOfMemory. This has be reported often. I will try to call `gc()` manually, but it should be called automatically as soon as memory is low.... – Jonas May 20 '14 at 14:11
  • `gc()` does not reduce memory load – Jonas May 20 '14 at 14:33
  • It's because of this issue that I gave up on the `xlsx` package and have moved to `readxl`, which is [faster](http://stackoverflow.com/questions/6099243/read-an-excel-file-directly-from-a-r-script/31734198#31734198) – MichaelChirico Feb 25 '16 at 02:15

0 Answers0