Yeah Jim !
That's absolutely correct, i agree with your point of making all the calculations beforehand i.e before starting of the real application. i have made some changes in your code and now it is looking like this.
public long getAbsoluteTotalMemory()
{
byte[] reserve;
LinkedList list=new LinkedList();;
try
{
reserve = new byte[10000]
for ( ; ; )
{
list.add(new byte[10000]);
}
}
catch (OutOfMemoryError e)
{
reserve = null;
list.clear();
list=null;
System.gc();
return Runtime.getRuntime().totalMemory();
}
}
Surprisingly, this is working very fine without even allocating
-mx memory to the
java process, if i look into the Task Manager, as against the previous code.
Saurabh