Results 1 to 4 of 4
  1. #1
    Ms.Ranjan is offline Member
    Join Date
    Jun 2008
    Posts
    85
    Rep Power
    0

    Default Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

    Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
    at java.util.ArrayList.ensureCapacity(ArrayList.java: 169)
    at java.util.ArrayList.add(ArrayList.java:351)


    My program is looping through three files of capacity 91,80,199 KB.I am using eclipse.In the run configuration of my program i gave -Xms256M -Xmx512M in the vm arguments section and tried running the program i still get the same error.

    my eclipse.ini has this information,should i also change this information?

    org.eclipse.platform
    --launcher.XXMaxPermSize
    256m
    -vmargs
    -Xms40m
    -Xmx256m

  2. #2
    neilcoffey is offline Senior Member
    Join Date
    Nov 2008
    Posts
    286
    Rep Power
    6

    Default

    No, don't change eclipse.ini. That sets the amount of memory etc for the Eclipse IDE itself, and that's not where the problem is occuring.

    It sounds as though you're putting the settings in the right place. N.B. Just because the files are 91MB on disk doesn't mean that they'll be that size in whatever structure you're putting the contents to in Java. You seem to be adding the data to an arraylist of some kind. What actual objects are you putting in the array list. Have you properly considered the memory use and overhead of Java objects in your estimate of how much heap space you need to allocate?

    On the page I mentioned, see the link to the Classmexer agent: this lets you query VM for the actual memory usage of an object. So you can load a small sample of your data into whatever format you're storing it in in memory, then query the usage of that sample and scale up accordingly.
    Last edited by neilcoffey; 04-22-2009 at 06:53 PM. Reason: added Classmexer link

  3. #3
    Ms.Ranjan is offline Member
    Join Date
    Jun 2008
    Posts
    85
    Rep Power
    0

    Default

    Thanks for the reply i will go through the articles...i store the contents of the file as string in a hashmap.

  4. #4
    neilcoffey is offline Senior Member
    Join Date
    Nov 2008
    Posts
    286
    Rep Power
    6

    Default

    Hash maps are generally fairly memory-hungry. Remember that for each item you add, in addition to the fact that you're storing a key and a value, the hash map also has an internal entry object.

    Remember too that Strings, in addition to their memory overhead for just being an object, use two bytes for every character. See my example CompactCharSequence class for a way to store strings one byte per character (provided they don't contain any "exotic" characters...).

Similar Threads

  1. Replies: 10
    Last Post: 05-11-2009, 11:56 AM
  2. Replies: 16
    Last Post: 07-24-2008, 11:45 AM
  3. Replies: 14
    Last Post: 06-12-2008, 08:36 AM
  4. Replies: 1
    Last Post: 08-07-2007, 07:10 AM
  5. Replies: 1
    Last Post: 07-25-2007, 10:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •