Setting heap size in eclipse!?

Associate
Joined
23 Aug 2004
Posts
1,493
I was an idiot and deleted some database tables so I need to recreate them in jave using eclipse. I'm reading a file, after 150 thousand lines my program aborts with the error, run out of heap space. This happened when I first created and populated the tables so i increase the heap size under run - open run diag - args - program args with the argument being -Xmx 1024m. This should be more than enough, but it keeps giving the same out of space error. any tips?

---edit---

doesn't matter what size heap i use, i can say max of 1mb and it fails at the same point?!
 
Two problems I can see

1) You're using "program args". These are passed to your application as the String[] in main(). You need to put it in "VM arguments"

2) There should be no spaces in the argument -Xmx1024m

Try running this class to check the settings take effect. For me it bombs out after 7.7 million with default memory settings.

Code:
public class OutOfMemoryTest {

	public static void main(String[] args) {
		
		long[] tmp;
		int size = 6000000;
		
		while(true) {
			size += 100000;
			tmp = new long[size];
			System.out.println("Allocated array size: " + size);
		}
	}
}
 
I just came across a much easier approach :)

Code:
// Get current size of heap in bytes
long heapSize = Runtime.getRuntime().totalMemory();
	    
// Get maximum size of heap in bytes. The heap cannot grow beyond this size.
// Any attempt will result in an OutOfMemoryException.
long heapMaxSize = Runtime.getRuntime().maxMemory();
	    
System.out.println("Current heap: " + (heapSize/1048576) + "MB");
System.out.println("Max heap:      " + (heapMaxSize/1048576) + "MB");
 
Back
Top Bottom