This time, the program allocated 2048KB of objects during the initialization
phase. Then it started the test loop phase of allocating 1024KB of objects
before release the same amount of objects.
By looking at the output, the periodic change of memory requirement between
2048KB and 3072KB had no impact on the garbage collection process.
Obviously, we had a problem here. My program crashed at second 42
with the "out of memory" exception.
At that time, the free memory decreased to 2%. But there were 3072KB of
dead objects that could be collected to gain more free memory.
Why the JVM did not collect the dead objects? Can anyone help to explain?
I believe the answer is related my guessed rule that the JVM will reserve
the same amount of memory as collected garbages.
At second 42 in our test, 8128 (total memory) - 4608 (active objects)
- 3072 (reserved memory) = 448 (free memory), not enough to work with.