Henry Wong wrote:
A copy collector splits the heap in half and move objects between the two halves during the GC cycle. And yes, "it will cost a lot".
The theory behind using a copy collector for the new generation objects, is that most objects do not last very long.
We divide objects into young generation and tenured generation. Question is, how to divide ? Yes, the object defined inside a method definitely is short lived, should be in young generation. My coding above is not this case, so local object is not our topic here.
Objects defined in the instance level, how to divide them into young generation and tenured generation ?
All objects, that are instantiated on the heap, goes to the new generation portion of the heap. After a few new generation GC cycles, depending on configuration, they should be promoted to the old generation portion of the heap.
Now, if you want to know how the GC is configured, then you should google for a java GC tuning guide.