Results 1 to 3 of 3
Thread: java.lang.OutOfMemoryError
- 09-18-2008, 11:47 AM #1
Member
- Join Date
- Sep 2008
- Posts
- 3
- Rep Power
- 0
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!
- 09-18-2008, 12:12 PM #2
Senior Member
- Join Date
- May 2008
- Location
- Makati, Philippines
- Posts
- 234
- Rep Power
- 10
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.
- 09-18-2008, 12:21 PM #3
Member
- Join Date
- Sep 2008
- Posts
- 21
- Rep Power
- 0
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
-
java.lang.OutOfMemoryError: Java heap space
By paul in forum Advanced JavaReplies: 11Last Post: 06-12-2010, 05:30 PM -
java.lang.OutOfMemoryError: unable to create new native thread
By jai135 in forum Java ServletReplies: 11Last Post: 09-01-2008, 10:56 AM -
java.lang.OutOfMemoryError in a web service client
By elchape in forum Advanced JavaReplies: 4Last Post: 06-28-2008, 05:21 PM -
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
By Eku in forum NetBeansReplies: 14Last Post: 06-12-2008, 08:36 AM -
java.lang.OutOfMemoryError with java vector
By mary in forum New To JavaReplies: 3Last Post: 08-03-2007, 10:55 AM
Bookmarks