Results 1 to 3 of 3
  1. #1
    vidhya.sk is offline Member
    Join Date
    Sep 2008
    Posts
    3
    Rep Power
    0

    Default java.lang.OutOfMemoryError

    Hi everyone..

    I am getting an error message like this when i run my code:

    Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
    at java.util.Arrays.copyOfRange(Unknown Source)
    at java.lang.String.<init>(Unknown Source)
    at java.io.BufferedReader.readLine(Unknown Source)
    at java.io.BufferedReader.readLine(Unknown Source)
    at ascii_reader.main(ascii_reader.java:274)

    I am using an array of vectors to store information from a file and then retrieving that information.

    This error occurs when i try to read files of size > 20 MB.

    I tried changing the memory allotment to heap in the eclipse.in file from 256m to 512m..
    Still the error persists..

    Can anyone help me out with this issue?

    Thanks!

  2. #2
    Eku
    Eku is offline Senior Member
    Join Date
    May 2008
    Location
    Makati, Philippines
    Posts
    234
    Rep Power
    7

    Default

    That will really knock your system down. May i suggest that dont load the whole file all at once. ^_^ you can try about 1000 lines at a time and when your done load the next 1000 lines =)
    Mind only knows what lies near the heart, it alone sees the depth of the soul.

  3. #3
    nishant is offline Member
    Join Date
    Sep 2008
    Posts
    21
    Rep Power
    0

    Default

    hi....how r u.....

    Can't really say because we don't know what your data is and what you want to do with it. If you can handle the data in a streaming fashion (i.e. line by line or in other increments smaller than the entire file), you don't need to read everything into one big buffer first, but you read each part, handle it, and discard or reuse the buffer.

    If you need to handle that much data in one StringBuffer (btw StringBuilder is recommended as of Java 1.5), there's really no other option than to increase the heap space for the JVM (default is 64MB)


    You have two choices:

    1) Don't read in the whole file at once. Read in and process a line or small group of lines at a time. This is probably the better solution. It's unlikely that you actually need the whole file in memory as a single string.

    2) Increase the heap size at VM startup. I'm pretty sure you can still do that with a double clickable jar file. If that wasn't what you meant--that is, if that part about "...standalone routine from a jar file" means that it's a library that is being used in some other application, then it's the user's job to give his VM enough memory.

    ...might this help!
    bye

Similar Threads

  1. java.lang.OutOfMemoryError: Java heap space
    By paul in forum Advanced Java
    Replies: 11
    Last Post: 06-12-2010, 05:30 PM
  2. Replies: 11
    Last Post: 09-01-2008, 10:56 AM
  3. java.lang.OutOfMemoryError in a web service client
    By elchape in forum Advanced Java
    Replies: 4
    Last Post: 06-28-2008, 05:21 PM
  4. Replies: 14
    Last Post: 06-12-2008, 08:36 AM
  5. java.lang.OutOfMemoryError with java vector
    By mary in forum New To Java
    Replies: 3
    Last Post: 08-03-2007, 10:55 AM

Posting Permissions

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