Increase Java Memory Allocation
I'm attempting to read a 15mb xlsx file for a program I'm writing using SmartXLS.
I have been getting errors and I have been attempting to figure out the cut-off for when I will be allowed to read the sheet.
At 15 mb, I was receiving a SmartXLS error.
At 14 mb, I was receiving the java.lang.OutOfMemoryError: Java heap space
At 10 mb, I am still receiving the OutOfMemoryError
At 5 mb, it allowed me to read the xlsx.
I assume this means I need to get Java to allocate more memory. Is anyone able to explain to me how?
Re: Increase Java Memory Allocation
call the JVM with the following arguments:
-Xms for initial heap size (default: 32 MB)
-Xmx for max heap size (default: 128 MB)
So, for example say you wanted to use a max heap size of 512MB:
Java -Xmx512m theClass
(I don't know if you can put a space between Xmx and the size, but I know it works without the space)
Also, note the "m" at the end. This specifies 512 mega bytes, otherwise trying to set a 512 byte heap would cause Java to fail.
Re: Increase Java Memory Allocation
I've never done this before and I'm looking through Google now. But how exactly to I "call the JVM"?
Re: Increase Java Memory Allocation
Now I have managed to cut it down to 2 xlsx files, 1 at 10mb and the other at 5mb. It currently cannot read the 10mb one. However, SmartXLS can read the xlsx file in different ways. This is just a thought, but would the memory useage be different if a different method of opening the file was used? SmartXLS can read by URL, InputStream, or File Path. I am currently using the File Path method.
Re: Increase Java Memory Allocation
Whenever you run Java simply add the argument.
Example:
>> rem run java with 512 MB max heap size
>> Java -Xmx512m myClass
If you're using an IDE, you'll have to look through the IDE documentation for how to pass arguments to the JVM (make sure it's not program arguments! Those are different).
In Eclipse, this is done by clicking that little arrow next to the run/debug button, go to Run Configurations -> Arguments, then add the JVM arguments under VM arguments.