" java.lang.OutOfMemoryError" in R

hello everybody
after running this line of code I get this error. why?
i did not have this error yesterday and it worked well.

df = read.xlsx("C:/Users/.....xlsx", 1)

Error in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl, :
java.lang.OutOfMemoryError: GC overhead limit exceeded

It's impossible to say since only you have access to this file.

However, as one suggestion, you can try reading your Excel file using a different package - readxl(more info on how to install and use it here - https://github.com/tidyverse/readxl).

The java.lang.OutOfMemoryError means that your program needs more memory than your Java Virtual Machine (JVM) allowed it to use.

How to Track the error?

  • Increase the default memory your program is allowed to use using the -Xmx option (for instance for 1024 MB: -Xmx1024m). By default, the values are based on the JRE version and system configuration. NOTE: Increasing the heap size is a bad solution, 100% temporary, because you will hit the same issue if you get several parallel requests or when you try to process a bigger file.

  • Find the root cause of memory leaks with help of profiling tools like MAT, Visual VM , jconsole etc. Once you find the root cause, You can fix this memory leaks.

  • Optimize your code so that it needs less memory, using less big data structures and getting rid of objects that are not any more used at some point in your program.

How to avoid this issue?

  • Use local variables wherever possible.
  • Release those objects which you think shall not be needed further.
  • Avoid creation of objects in your loop each time.
  • Try to use caches.
  • Try to move with Multy Threading.

In my experience any dependence on Java interop from R tends to be fairly brittle, so if there is a way to eliminate Java dependency I'd almost always recommend going this route. Hence, my recommendation to use readxl that doesn't use Java at all.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.