Intro Two Reduce Heap Memory Method For Java
這篇介紹Two Reduce Heap Memory Method For Java。
Example I
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| Before: double[][] arrays = new double[1000][1000];
for (int i = 0; i < 10000; i++) { for (int j = 0; j < 10000; j++) { double[][] temp = arrays[i][j]; } }
After: double[][] arrays = new double[1000][1000];
for (int i = 0; i < 10000; i++) { double[] search = arrays[i]; for (int j = 0; j < 10000; j++) { double[][] temp = search[j]; } }
|
Example II
1 2 3 4 5 6 7 8 9 10 11 12 13
| Before:
for (int i = 0; i < 10000; i++) { double[] arrays = new double[10000]; }
After: double[] arrays = new double[10000];
for (int i = 0; i < 10000; i++) { Arrays.fill(arrays, 0); }
|