????GC??Java???
???????????? ???????[ 2014/6/20 11:21:20 ] ??????????????? java
???????????????????
????GC?????????????????????ROOT????????????д????????????????????????
?????????????GC????????????????Old Generation?С?
??????????????£????????Old Generation???????????Young Generation?????????????YoungGC??????У?????????????????
????Hotspot JVM??????YoungGC??????????????YoungGC?????Old Generation?е??????????????? ????(Card Table) ??????
?????????????Old Generation?е????????Young Generation?е????????μ????ù???????????????????????????????????????(dirty)????YoungGC????????????Щdirty??????????
???????????????????????ù???????????仯???????п????????й????г????????????????????????????Щ??????????????????????dirty??
??????????????????ù??????????????迨???????????????????????
???????????????????????????????????ò?????final??????????????Immutable Objects??
??????????????null????
???????????Java?????ж?????????????н???????????null??????GC???????????????????
????List<String> list =newArrayList<String>();
????// some code
????list =null;// help GC
???????????????????GC???????????????????????′???????
???????ü???? @rednaxelafx ??HLL VMС?????????????????????????????????????????
??????????????????????????????????????????????null???????????????GC??
????????????£??????????????κκ????
???????????????????????“???”????ɡ?
????GC??????????????????
?????塢???????GC
????????Java??????????????????漼?????
???????Thread.yield()?ó?CPU?????????????
???????System.gc()????GC??
?????????JVM?????????????£???System.gc()??JVM???????????????????GC???????FullGC???????????е???????????????????????
????So?????????μ?????
????Never use Thread.yield()??
????Never use System.gc()??????????????????Native Memory??
??????????и?Native Memory????????????????3?????
????· ?????NIO????NIO????Mina/Netty??
????· ?????DirectByteBuffer????????????
????· ?????MappedByteBuffer????????
????????Native Memory??????FullGC??????CMS GC????????????????????????????б????????????????System.gc()?????????????
??????????????Щ????е?System.gc?????????NIO????Java RMI??????????????????м???-XX:+DisableExplicitGC?????????GC??
????????????и?????????????????System.gc()??????????3??????μ???????????????????OOM????????????CMS GC???????????????????????-XX:+ExplicitGCInvokesConcurrent??
????????System.gc()??????ο? @bluedavy ???????£?
????· CMS GC???????Direct ByteBuffer?????
????· ????Java???????????????
????· java.lang.OutOfMemoryError:Map failed
??????????????????????С
????Java?????????????????????????????????????????????????С????????????????????????????
???????????????ζ????д?????????????????
?????????Щ????????????????????StringBuilder??StringBuffer??ArrayList??HashMap???????????????????ArrayCopy????????????????????????????????????????????????????飬????????Щ??????????????????GC?????
??????Щ????????????????????????????????С???????????????Щ??С???????????????????????????????
??????????????????????????????????????????????????????????????HashMap??????????????????(loadFactor)????
????Google Guava???????????????????????????????????????磺
????Lists.newArrayListWithCapacity(initialArraySize);
????Lists.newArrayListWithExpectedSize(estimatedSize);
????Sets.newHashSetWithExpectedSize(expectedSize);
????Maps.newHashMapWithExpectedSize(expectedSize);
????????????????????????С????????????????Guava?????ɡ?
??????????
????????????????ι??????????????ArrayList????????????????OOM????????????л??£?
???????????????????·?????????????
?????????????
??????????
??????
???·???
??????????????????
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