How to avoid java.lang.OutOfMemoryError
I have a program which will consume huge memory and OOM sometimes. To avoid, I try to get the size of JVM heap size, if required than available, than exit. Below is exmaple.
But the free memory number is not very correct. Is there any way to get the accurate number of JVM heap size to deal with my case?
Runtime runtime = Runtime.getRuntime();
int a=new int[(int)freeMem*9+1];
Thanks in advance.