public class MapLeaker {
    public ExecutorService exec = Executors.newFixedThreadPool(5);
    public Map taskStatus
        = Collections.synchronizedMap(new HashMap());
    private Random random = new Random();
    private enum TaskStatus { NOT_STARTED?? STARTED?? FINISHED };
    private class Task implements Runnable {
        private int[] numbers = new int[random.nextInt(200)];
        public void run() {
            int[] temp = new int[random.nextInt(10000)];
            taskStatus.put(this?? TaskStatus.STARTED);
            doSomeWork();
            taskStatus.put(this?? TaskStatus.FINISHED);
        }
    }
    public Task newTask() {
        Task t = new Task();
        taskStatus.put(t?? TaskStatus.NOT_STARTED);
        exec.execute(t);
        return t;
    }
}
????? 1 ??? MapLeaker GC ?????ó?????С????????仯???????????????????й????????????????????ó????У??????????????????????????????? GC ?????????????????????ú????????

????? 1. ????????????????????

??????????????й????????????????????????????????????????????????????????????????з???????????Щ???????????????????????????й??????????????Щ???? —— ????? hprof ?????????????????????? hprof ?????????????????????? -Xrunhprof:heap=sites ?????? JVM??

?????嵥 3 ??????????ó?????????? hprof ??????????????hprof ????????ó??????????????? kill -3 ???? Windows ?а? Ctrl+Break ???????÷??????????ο???????Map.Entry??Task ?? int[] ?????????????????

?????嵥 3. HPROF ???????? Map.Entry ?? Task ?????????


SITES BEGIN (ordered by live bytes) Fri Oct 28 16:30:48 2005
          percent          live          alloc'ed  stack class
 rank   self  accum     bytes objs     bytes  objs trace name
    1 70.13% 70.13%   5694888 13909   5694888 13909 300305 int[]
    2 18.27% 88.40%   1483976   68 278273632 13908 300321 int[]
    3  4.11% 92.51%    333816 13909    333816 13909 300310 java.util.HashMap$Entry
    4  2.74% 95.25%    222544 13909    222544 13909 300304 com.quiotix.dummy.MapLeaker$Task
    5  2.42% 97.67%    196640    2    262192    11 300325 java.util.HashMap$Entry[]
    6  0.66% 98.33%     53680 3355    222464 13904 300324 java.util.concurrent.LinkedBlockingQueue$Node
SITES END
SITES BEGIN (ordered by live bytes) Fri Oct 28 16:31:32 2005
          percent          live          alloc'ed  stack class
 rank   self  accum     bytes objs     bytes  objs trace name
    1 77.07% 77.07%  41176024 100020  41176024 100020 301069 int[]
    2 12.98% 90.05%   6933768  359 2001885688 100020 301093 int[]
    3  4.49% 94.55%   2400480 100020   2400480 100020 301082 java.util.HashMap$Entry
    4  3.00% 97.54%   1600320 100020   1600320 100020 301068 com.quiotix.dummy.MapLeaker$Task
    5  1.96% 99.50%   1048592    1   2097248    14 301104 java.util.HashMap$Entry[]
    6  0.05% 99.55%     25936 1621   1600240 100015 301101 java.util.concurrent.LinkedBlockingQueue$Node
SITES END