Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Increase Java Memory Allocation

  1. #1
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default 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?


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default 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.

  3. #3
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default 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"?

  4. #4
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default 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.

  5. #5
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default 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.

Similar Threads

  1. Memory Handling -de allocate memory in Java
    By 19world in forum Java Theory & Questions
    Replies: 4
    Last Post: June 15th, 2010, 04:05 AM
  2. Out of memory work around for a java application (please help!)
    By javameanslife in forum Java Theory & Questions
    Replies: 5
    Last Post: January 22nd, 2010, 04:27 AM
  3. Out of memory - Java heap space
    By fraxx in forum Java Theory & Questions
    Replies: 4
    Last Post: November 24th, 2009, 05:26 AM
  4. Java memory management
    By trueacumen in forum Java Theory & Questions
    Replies: 5
    Last Post: August 12th, 2009, 02:40 AM
  5. Can we increase the stack size for JVM ?
    By prasanna in forum Java Theory & Questions
    Replies: 4
    Last Post: August 4th, 2009, 03:17 PM