Java GC Summary

Source: Internet
Author: User

Java GC Garbage Collector overview
关于JavaGC,有三件事情需要了解1.那些内存需要回收2.什么时候回收3.这么回收
So judging object is dead reference counting method
用一个计数器表示对象的引用,对象被引用就+1,,引用失效-1.不过这个算法有一个问题,就是对象的相互引用,会使对象无法回收。比如A引用B,B引用A,这两个对象实际上已经没用了,但是无法回收。现在的虚拟机都不会通过该算法来判断对象
Accessibility analysis algorithm
这个算法通过一系列称为"GC Roots"的对象作为起始点,当一个对象到GC Roots没有任何引用链相连时,则证明该对象没用了。"GC Roots"包括:1.虚拟机栈引用对象(局部变量表)2.方法去静态属性引用对象3方法去中常量引用的对象4,本地方法栈中JNI引用对象具体结构如

Garbage collection algorithm tag-purge algorithm
如同名字一样,分为标记和清除两步,这是最基本的收集算法,其他算法都是基于这个思路并且优化的。这算个标记和清除效率都不高,而且清除完后有很多不连续的内存碎片。


Replication Algorithms
就是将内存一分为二,将存活的对象复制到另一半,将原来的对象全部删除。这个算法很浪费内存,浪费了一半的内存。现在商业的虚拟机新生代都是采用这个算法但并不是1:1的比例,实际比例8:1,会划分为一个eden和两个Survivor空间,将eden和其中一个Survivor中存活的复制到另一个Survivor中,空间不足时以来老年代进行分配担保


Tagging-sorting algorithms
与清除一样,只是不直接清除,是先将存活的对象向一端移动,然后清理掉边界之外的内存


Generational collection Algorithms
将内存分为新生代、老年代和永生代三个区域,新生代因为每次会有大量对象死去,使用复制算法,老年代存活率高,没有多余空间对它进行分配担保,使用标记-清理或者标记-整理算法

Java GC Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.