???????????????????
????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????????????л??£?
???????????????????·?????????????
?????????????
??????????