
Originally Posted by
grahamhughes
Exactly what figure does it go to?
it actually overran the int limit and became a negative value. i did a try catch, but it caught nothing. i thought it's quite odd too...
anyway, the code has been modified since to take 1024 * 2000000 bytes at max.
Code:
try{
while(true){
System.out.println("\n\tTesting heap size: " + heapSize);
byte [] test = new byte [heapSize];
System.out.println("\tTest OK");
test = null;
//up to 10MB
if(heapSize < (1024 * 10000) && heapSize >= 0){
heapSize += granularity;
}
//at 10MB
else if(heapSize == (1024 * 10000)){
//set granularity to 1MB
granularity = 1024 * 1000;
heapSize += granularity;
}
//from 10MB to 100MB
else if(heapSize > (1024 * 10000) && heapSize < (1024 * 100000)){
heapSize += granularity;
}
//at 100MB
else if(heapSize == (1024 * 100000)){
//set granularity to 10MB
granularity = 1024 * 10000;
heapSize += granularity;
}
//from 100MB to 1GB
else if(heapSize > (1024 * 100000) && heapSize < (1024 * 1000000)){
heapSize += granularity;
}
//at 1GB
else if(heapSize == (1024 * 1000000)){
//set granularity to 100MB
granularity = 1024 * 100000;
heapSize += granularity;
}
//upwards of 1GB
else if(heapSize > (1024 * 1000000) && heapSize < (1024 * 2000000)){
heapSize += granularity;
}
else if(heapSize == (1024 * 2000000)){
break;
}
}//while
}
catch(OutOfMemoryError e){
//1 granularity less
heapSize -= (granularity);
System.out.println("\tMaximum allowed file size: " + heapSize);
}
catch(Exception err){
System.out.println("\tException err: " + err.toString());
}
System.out.println("FileManager.findMaxHeapSize(): " + heapSize);
last print out:
Testing heap size: 2048000000
Test OK
FileManager.findMaxHeapSize(): 2048000000