Your guess is that if you have n bytes of free memory and m bytes are allocated, then you will have nm bytes of free memory.
This is a rational hypothesis, but it is false in the presence of asynchronous garbage collectors, which will or will not do jsut memory compression on their own.
And even if you spent years studying the behavior of a particular JVM and accumulated deep wisdom and knowledge that allowed you to predict the effect of distribution on the result of freeMemory (), this knowledge may suddenly become useless when switching to another JVM or just update the current one.
Therefore, trust us elders and see Runtime.freeMemory()
as a kind of fun random number generator.
source share