Detailed well-versed documentation on troubleshooting XLConnect OutofMemoryError(java) GC overhead limit exceeded and the types of Out of Memory Error.
let me know if anything is needed. #bobrupakroy
2. Troubleshooting XLConnect
XLConnect package makes use of Java for a connection to .xlsx or .xls file to
provide high level API to a connection.
However during the course of time we might encounter ‘out of memory error’
from java while loading the workbook.
This is a issue of Java and not R. The default heap size for libraries that
XLConnect rely on rJava is 512MB and is relatively easy to exceed this size.
2) java.lang.OutOfMemoryError: GC overhead limit exceeded space
is atype of OutOfMemoryError in Java which comes when JVM spent too much
time doing garbage collection.
3. Types of OutOfMemoryError
There are different types of OutOfMemoryError in Java and each denotes
different type of resource problems e.g.
java.lang.OutOfMemoryError: Java heap space
This error means not enough heap memory to create new objects.
java.lang.OutOfMemoryError: Permgen space
This error means not enough memory in permanent generation of the heap to
load class metadata.
java.lang.OutOfMemoryError: Direct buffer memory
means not enough heap memory to allocate to direct byte buffer.
java.lang.OutOfMemoryError: unable to create new native thread
means your application has exceeded the limit to create threads.
4. Suggestions for OutOfMemoryError
If the application genuinely needs more memory than perform the
following exercises:
ü Increase the maximum heap size which is suitable for your
application e.g. -Xmx=1025m. For 32-bit JVM, we cannot set
maximum heap size more than 2Gb whether its Windows, Linux or
Solaris, it will throw invalid heap size error. If the application needs
more memory, it's better to switch to a 64-bit Java Virtual Machine.
Changing the maximum heap size can be done in different
combination of codes as well as code analysis.
1) Increase the JVM heap size using R Console:
>detach("package:XLConnect", unload=TRUE)
>options(java.parameters = "-Xmx1024m")
>library(XLConnect)
Note: this step must be performed prior to loading any packages.
5. Suggestions for OutOfMemoryError
2) Using the same R session over and over again without
restarting the R-Studio. Restarting the R-Studio can help to
allocate a fresh memory to the application.
3) Increase the Java memory using JAVA GUI
https://www.wikihow.com/Increase-Java-Memory-in-Windows-7
follow the link illustrates how to set the memory using
–xmx and –xms parameters
-xmx stands for max heap size and –xms minimum heap size for a
java process to start with.
Rupak Roy
6. 4) Free the Java Virtual Machine memory with
>xlcFreeMemory()
and
>xlcMemoryReport()
The final solution to this XLConnect Java dependency issue if
the JVM memory still persists is we can use alternative R
packages that as masked from XLConnect to read excel files
that has no java dependencies like open.xlsx, readxl.
Final Solution
Rupak Roy
7. NEXT:
Open.xlsx that uses C++ dependencies instead of
rjava(java)
Troubleshooting XLConnect
Rupak Roy