Should you first pick up the younger generation in complete garbage collection?

I am writing a program containing a generation garbage collector. There are only two generations. I ask myself: when I make a complete collection, can I get something (in terms of performance) by first collecting the younger objects, promoting the survivors to the old generation, and then collecting the old generation or just collecting all the garbage in one sweep ? I'm not sure how people usually do this.

Now I'm using a two-step method, since it was a little easier to implement, but maybe one step would be more efficient?

The garbage collector does not copy if that matters.

+6
garbage-collection
source share
1 answer

It depends on how often you promote the survivors. If you promote them often, then it looks like you will do much better by making the GC one-off. If you do not, then it looks like they will be very similar.

In any case, it seems that you are doing a little redundant work, doing this in two stages. For example, anyone who receives a promotion is in fact checked twice (once younger and again as old). Again, if this does not happen too often, I would stick with a simpler two-stage method (since you already have his work, and win it a little).

+5
source share

All Articles