Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does gen 0, gen 1, gen 2 trigger exactly?

Gen 0: So I read that gen 0 triggers when gen 0 exceeds a size threshold. But I also read that GC is not performed at a "new", because "new" merely slides an address forward. Then, when does it check it has exceeded the threshold to trigger the gen 0 GC?

Gen 1/2: Do gen 1/2 have their own size threshold that trigger GC? When do they consider the threshold? Is it the moment when survivors are promoted to the gen?

Does that mean for a gen 1 GC to occur it first checks gen 0, then promotes them to gen 1, only to find gen 1 has exceeded the threshold and so it check gen 1, and check gen 0 again?

And does that mean for a gen 2 GC to occur it first checks gen 0, then promotes them to gen 1, only to find gen 1 has exceeded the threshold and so it checks gen 1, and check gen 0 again. Then promotes gen 0 to gen 1 and gen 1 to gen 2, only to find gen 2 has exceeded the threshold and so it checks gen 2, gen 1 again, and gen 0 again again?

like image 636
ill mg Avatar asked Oct 27 '11 04:10

ill mg


1 Answers

After the CLR initialized, objects which are first added to the managed heap are defined as Gen0. When the GC executed, the generation of the objects which were not collected will increase by 1 level and became Gen1. Objects created after that are still Gen0. With objects are created, Only if the memory released by the Gen0 objects is not enough to create new objects, and the volume in Gen1 exceeds the capacity, GC will collect both Gen0 and Gen1 objects. After that, objects not collected in Gen1 will become Gen2, and objects not collected in Gen0 will become Gen1. Objects created after that are still Gen0.

like image 91
ojlovecd Avatar answered Oct 01 '22 13:10

ojlovecd