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: Java Heap Space

  1. #1
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,628
    Thanks
    25
    Thanked 322 Times in 300 Posts

    Default Java Heap Space

    I'm running into this exception when I'm really not expecting it. I'm trying to read in a 634kb Excel file and it throws that exception when I try it. The reason it doesnt make sense is because in other programs I have read and written 5mb Excel files without issue. Any thoughts as to why it is running out of memory on a file a fraction of the size of some of the files I can usually work with?

    Also, I could use a quick-fix for the time being, can anyone tell me how to increase the Java Heap Space?


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,264
    Thanks
    176
    Thanked 821 Times in 764 Posts
    Blog Entries
    5

    Default Re: Java Heap Space

    Command line parameter -Xmx512m or even -Xmx1g will increase the max heap size. As for the reason, could only guess without more details. Check you aren't duplicating the reads into memory, have other things in the program and this just pushes it over the edge, etc...

  3. #3
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,628
    Thanks
    25
    Thanked 322 Times in 300 Posts

    Default Re: Java Heap Space

    Well, prior to reading in the document, I did a System.out.println(Runtime.getRuntime().freeMemory ()); printout. The result was: 3655344.

    What does that tell me?


    EDIT: I typed: java -Xmx1g into the command prompt. Didn't do anything. I assume I did it incorrectly. If so, can you tell me actually how to do it?


    EDIT AGAIN: I tried something and I think the program just doesnt like the file. It cant seem to read in the 634kb file at any point in the program. However, it is capable of reading in a 1127kb file. Any guesses as to that?
    Last edited by aussiemcgr; September 8th, 2010 at 11:10 AM.

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

    Default Re: Java Heap Space

    Without looking at the source, there's no way for us to know what's wrong.

    When calling your program with an expanded heap space, you would use the following command line arguments:

    Java myClass -Xmx1g

    If you have an IDE (for example Eclipse), there's a section where you can pass VM arguments (not program arguments, these are different). Simply type -Xmx1g into there and it should start your program with 1 GB heap space.

  5. #5
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,628
    Thanks
    25
    Thanked 322 Times in 300 Posts

    Default Re: Java Heap Space

    I would provide my source, but its like 2,000 to 3,000 lines long and I believe I may be getting this because of a bug in the External Library I use to read .xlsx files. Emailed the makers, waiting for a response.

    EDIT: Here is the email response:
    SmartXLS use DOM to parse xml files embed in the xlsx/xlsm zip file.The DOM parser in java is very poor performance in memory using,it will throw exception if there are many xml content.The solution is add more memory to the java runtime engine.
    We also had another version which is more efficient in parsing xml(use less memory and more quick),but it must run on Java5 and above.We can also provide it to licensed user(no trial available,same function but only different xml parser).
    Last edited by aussiemcgr; September 8th, 2010 at 05:44 PM.

Similar Threads

  1. AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
    By nasi in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 25th, 2010, 10:37 PM
  2. Replies: 15
    Last Post: February 28th, 2010, 09:30 PM
  3. Java heap space error
    By Loki in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 27th, 2010, 09:47 PM
  4. Out of memory - Java heap space
    By fraxx in forum Java Theory & Questions
    Replies: 4
    Last Post: November 24th, 2009, 04:26 AM
  5. OutOfMemoryError (Java heap space)
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 21st, 2009, 10:56 AM