Out of heap space erorr
Hi guys,
My app is mainly a wordlist crunching program. Its a swing app.
There are two flat files about 10 MB each. The first part of the app is supposed to read all that data from the two sperate flatfiles and put them into two seperate Hashtables.
The first first file get loaded fine into the Hashtable. But during the loading of the second file, the program crashes giving a "out of Heap space" error.
Is this due to a memory leak? ( But thats not supposed to happen in Java) or the JVM with its default memory allocation cannot support processing such huge flat files?
I dont want to use the -Xmx option cuz thats what I am gonna use as a programmer. But when i deploy the application. nobody is going to use this option to run the program each time.
What do you think guys? How can this be solved?
Message was edited by:
arijit_datta
# 1
Hi , all objects in java live on Heap..As objects grow on the heap ,available space on heap will be decreased , In such cases you will get that error..
to solve the problem,unreachable objects needs to be deleted from the heap..
I hope the following can solve yr problem.
1) make null all unuseful object references ( all unused object refrences related to your first file..
obj=null;
2)Call System.gc() method before loading your second file or at end of the first file.
Consider this Example
import java.util.Date;
public class CheckGC {
public static void main(String [] args) {
Runtime rt = Runtime.getRuntime();
System.out.println("Total JVM memory: " + rt.totalMemory());
System.out.println("Before Memory = " + rt.freeMemory());
Date d = null;
for(int i = 0;i<10000;i++) {
d = new Date();
d = null;
}
System.out.println("After Memory = " + rt.freeMemory());
rt.gc(); // an alternate to System.gc()
System.out.println("After GC Memory = " + rt.freeMemory());
}
}
Thanks
RajaSekhar K