????2.????/????????
??????????漰??????????????????????????????????????????????????????.
??????????????????????????????????????????????????????????????????????????????????????????????е?????????????????????ν??"????".????????????????????????.???GC??????????????????.?????????????????????????????????????????????.????????????????????????.
????i.finalize()????.
??????????????????????????????????????????????????????????????????????.????????.????????.
????????finalize()????????????"????"???????????????????????????????.????GC?????????new????????????.????????????????????????????????????????????????????.??????finalize()???????????.
????????????Java?????new????????????????????????????????????????????????????????????????????????C???????????????????棬??????Java????????????????????????"???????"?????????????Java?е?native?????????JNI??C/C++???н?????????????????C/C++???????????C?????????????????????malloc()??????????????.??????malloc()????????????????????????????????free?????????????????????????free??????????棬????????潫????????????????????й??????free??C/C++?в??е?????????????????????free?????????finalize()?????????????е???.
????????????????????????????????????finalize()??????.????????????????????????????????.
????ii.Garbage Collection(GC)
??????????????.???????????????????????????ж?????.????????????????????.
????GC????????:
????????????????ò??????ü???????
????????????????????????????????????????????????????????????1???????????????????????????????????????????????null?????????????????????0????????????????????е?????б?????б???????????????0???????л?????????о???????????????????????????????????????к???????.????????????????????????.???????????????????????????????????0?????.???????????????????????.
???????ü????????????????????????????????????????JVM?????????????.
public class GcDemo {
public static void main(String[] args) {
GcObject obj1 = new GcObject(); //Step 1
GcObject obj2 = new GcObject(); //Step 2
obj1.instance = obj2; //Step 3
obj2.instance = obj1; //Step 4
obj1 = null; //Step 5
obj2 = null; //Step 6
}
}
class GcObject{
public Object instance = null;
}
????????????????????????????????????ü???????????????.

????1??GcObject???1?????ü?????1?????1?????ü???=1??
????2??GcObject???2?????ü?????1?????2?????ü???=1??
????3??GcObject???2?????ü??????1?????2?????ü???=2??
????4??GcObject???1?????ü??????1?????1?????ü???=2????е?4????GcObject???1?????2?????ü?????????2??
????5??????obj1???????Java???GcObject???1?????ü?????1??????1??
????6??????obj2???????Java???GcObject???2?????ü?????1??????1???????????GcObject???1?????2?????????????0????????????????ü?????????????????????????????潫?ò??????????????????й???
?????????5-6??????????.

???????????ü???????JVM????а????????.???JVM????????????????????????????????.
???????????:
??????????Hotspot ?е?minor GC???????????.???е?????????.??п???????????????????????????????????.???????е???????BFS??(??:???????????????).?????????.??????????е????н??.?????????????????????????????????????.???BFS???????????????.????minor GC??????Cheney???????.??????GC Roots????????ж??.??Щ????洢????????е???.?????????????.???????????????.?????????????????.
????GC Roots???????????????JNI???????????????????????????????????????????????о???????????????????????.

????reference1->???????1??reference2->???????2??reference3-> ???????4??reference3->; ???????4 ->???????6??
????????ó????????1??2??4??6??????GC Roots???????????????????GC????????????????????3??5???????????????????κ????GC Roots??????????????GC Roots?????????????GC???????????????????????????????????GcObject???1?????2????????ü???????????0??????????????????????GC Roots????????????????????????????????????????ü?????????GC???????????????????????????????????????
???????????????:????????????????????????е?.???????????:

????????????????.???????new????????????涼????з?????????????????????????????????????????????Eden??Survivor??????Survivor??FromSpace??ToSpace???????????????????????????????????????棬Eden??????????????????????Survivor?У?????????С??????-Xmn??????????????-XX:SurvivorRatio??????Eden??Survivor??????????????????????????о?????????????? (???Minor GC) ??????????.??????Cheney????????From?????????????????.????GC?????????????.
????Java?????????????????????????????????-????????-??????????????.???????????????????????ν????????????????????????л?????????????.?????????????-??????????????????????в??????????ж?????????????.??ν????????????????-???????-??????????л?.??????????-????????-???????????????????ж?????Java???????????????????.