你的位置:首页 > 信息动态 > 新闻中心
信息动态
联系我们

Java: Garbage Collection

2021/12/8 5:49:24

It uses Mark and Sweep strategy to clean the heap, which is the place where we store all the objects:
Mark – it is where the garbage collector identifies which pieces of memory are in use and which are not
Sweep – this step removes objects identified during the “mark” phase

but so many objects in heap, how can we decide which part is unreferenced and which is using now?
heap is divided in to few parts of generations:
Young Generation, Old or Tenured Generation
The Young Generation is where all new objects are allocated and aged. When the young generation fills up, this causes a minor garbage collection. Minor collections can be optimized assuming a high object mortality rate. A young generation full of dead objects is collected very quickly. Some surviving objects are aged and eventually move to the old generation.
The Old Generation is used to store long surviving objects. Typically, a threshold is set for young generation object and when that age is met, the object gets moved to the old generation. Eventually the old generation needs to be collected. This event is called a major garbage collection.