Java??????????????????
?????Darker ???????[ 2016/7/6 15:13:41 ] ??????????????????? Java
????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???????????????????.
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11