saadwharton
Programmer
I have a Java program with a class. The class has a private data member which is an array of integers. The array has 4 million data members. I initialize all 4 million data members with 0. When initializing, the program runs out of Heap memory when the loop iteration gets close to the 1 millionth data item.
Here is the class code:
class MyClass {
private:
int [] a ;
public:
MyClass() {
a = new int[4000000] ;
for (int i=0;i<4000000;i++) {
a = 0 ;
}
}
}
I tried this on a machine running Windows Vista with 1 GB of DDR RAM. The IDE is Eclipse.
I found instructions to increase the amount of heap space available to Eclipse. Basically, I set the Xms and Xmx arguments to high numbers (512M and 1024 M) respectively. But this does not get rid of the error.
How can I work with these 4 million array items in the limited memory that I have? Why does the JVM not use Virtual Memory when it runs out of memory? Available virtual Memory is much larger than real memory - since its size is constrained by the amount of free disk space.
Thanks-in-advance to the person who helps with this.
Sincerely,
Saad