//Takes the actual samples, recording them in the two arrays.
//We expand the arrays when they get full up.
if (sampleSize >= freeMemory.length)
{
//just expand the arrays if they are now too small
long[] tmp = new long[2 * freeMemory.length];
System.arraycopy(freeMemory, 0, tmp, 0, freeMemory.length);
freeMemory = tmp;
tmp = new long[2 * totalMemory.length];
System.arraycopy(totalMemory, 0, tmp, 0, totalMemory.length);
totalMemory = tmp;
}
freeMemory[sampleSize] = runtime.freeMemory();
totalMemory[sampleSize] = runtime.totalMemory();
//Keep the maximum value of the total memory for convenience.
if (max < totalMemory[sampleSize])
max = totalMemory[sampleSize];
sampleSize++;