欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Java8 String內(nèi)存優(yōu)化之字符串常量池詳解

 更新時間:2023年07月31日 15:54:34   作者:osnot  
這篇文章主要介紹了Java8 String內(nèi)存優(yōu)化之字符串常量池,具有很好的參考價值,希望對大家有所幫助,

前言

工作中遇到一個場景,需要在本地緩存大量信息,上百萬數(shù)量級,耗費了大量內(nèi)存4~5G,調(diào)研發(fā)現(xiàn)其大部分是String類型文本,因機器內(nèi)存有限,故希望減少該內(nèi)存占用,從String字段入手。

本文章是實驗不同情況下String占用內(nèi)存的表現(xiàn)。

環(huán)境

  • mac os 10.12.6
  • java version “1.8.0_112”
  • Java™ SE Runtime Environment (build 1.8.0_112-b16)
  • Java HotSpot™ 64-Bit Server VM (build 25.112-b16, mixed mode)
  • IntelliJ idea
  • G1垃圾回收器

實驗思路

結(jié)合網(wǎng)上的一些查詢,Java 8中字符串已經(jīng)放到堆上存儲,故沒有大小限制;

另外如果內(nèi)存不足時會GC釋放掉不再使用的字符串內(nèi)存,故設(shè)計實驗如下:

編號名稱目的
1存放近1G的字符串內(nèi)存作為2對照實驗
2存放近1G的字符串內(nèi)存-存入字符串常量池證明字符串內(nèi)存在堆上,無大小限制
3存放近1G的字符串內(nèi)存-相同字符作為4對照實驗
4存放近1G的字符串內(nèi)存-相同字符-字符串常量池證明字符串常量池可復(fù)用內(nèi)存
5存放超過jvm內(nèi)存的字符串內(nèi)存-字符串常量池作為6對照實驗
6存放超過jvm內(nèi)存的字符串內(nèi)存-字符串常量池-釋放內(nèi)存證明字符串常量池可被釋放

實驗1和實驗2-字符串內(nèi)存無大小限制

實驗1-存放近1G的字符串內(nèi)存

public static void main(String[] args) throws InterruptedException {
        System.out.println("--begin...");
        String[] result = test1_1();
        System.out.println("--end");
        System.out.println("--gc...");
        System.gc();
        System.out.println("--gc end");
    }
    private static String[] test1_1() {
        //jvm:-Xmx1G -XX:+PrintGCDetails -XX:+UseG1GC
        String[] array = new String[35 * 1024 * 1024];
        //37335040(3700萬)次循環(huán)
        for (int i = 0; i < 35 * 1024 * 1024; i++) {
            String str1 = new String("A");
            array[i] = str1;
            if (i % 1024 * 1024 == 0) {
                System.out.println("now i=" + i);
            }
        }
        return array;
    }

最后輸出:

now i=36696064
now i=36697088
now i=36698112
now i=36699136
–end
–gc…
[Full GC (System.gc()) 1005M->980M(1024M), 3.8400925 secs]
[Eden: 3072.0K(44.0M)->0.0B(51.0M) Survivors: 7168.0K->0.0B Heap: 1005.5M(1024.0M)->980.4M(1024.0M)], [Metaspace: 3345K->3345K(1056768K)]
[Times: user=5.63 sys=0.23, real=3.84 secs]
[GC concurrent-mark-abort]
–gc end
Heap
garbage-first heap total 1048576K, used 1003938K [0x0000000780000000, 0x0000000780102000, 0x00000007c0000000)
region size 1024K, 1 young (1024K), 0 survivors (0K)
Metaspace used 3351K, capacity 4564K, committed 4864K, reserved 1056768K
class space used 369K, capacity 388K, committed 512K, reserved 1048576K

實驗2-存放近1G的字符串內(nèi)存-存入字符串常量池

String.intern()方法可以從字符串常量池中獲取,如不存在則會添加到字符串常量池中,所以本實驗使用該方法:

public static void main(String[] args) throws InterruptedException {
        System.out.println("--begin...");
        String[] result = test1_1();
        System.out.println("--end");
        System.out.println("--gc...");
        System.gc();
        System.out.println("--gc end");
    }
    private static String[] test1_1() {
        //jvm:-Xmx1G -XX:+PrintGCDetails -XX:+UseG1GC
        String[] array = new String[35 * 1024 * 1024];
        //37335040(3700萬)次循環(huán)
        for (int i = 0; i < 35 * 1024 * 1024; i++) {
            String str1 = String.valueOf(i).intern();
            array[i] = str1;
            if (i % 1024 * 1024 == 0) {
                System.out.println("now i=" + i);
            }
        }
        return array;
    }

最后輸出:

now i=16506880
now i=16507904
now i=16508928
now i=16509952
[GC pause (G1 Evacuation Pause) (young) (to-space exhausted), 0.5090989 secs]
[Parallel Time: 497.8 ms, GC Workers: 4]
[GC Worker Start (ms): Min: 159566.9, Avg: 159566.9, Max: 159567.0, Diff: 0.1]
[Ext Root Scanning (ms): Min: 129.4, Avg: 131.1, Max: 132.8, Diff: 3.4, Sum: 524.3]
[Update RS (ms): Min: 0.8, Avg: 1.1, Max: 1.4, Diff: 0.7, Sum: 4.6]
[Processed Buffers: Min: 1, Avg: 1.8, Max: 2, Diff: 1, Sum: 7]
[Scan RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
[Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
[Object Copy (ms): Min: 363.3, Avg: 365.3, Max: 367.1, Diff: 3.7, Sum: 1461.0]
[Termination (ms): Min: 0.0, Avg: 0.3, Max: 0.5, Diff: 0.5, Sum: 1.0]
[Termination Attempts: Min: 1, Avg: 1.0, Max: 1, Diff: 0, Sum: 4]
[GC Worker Other (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.1]
[GC Worker Total (ms): Min: 497.7, Avg: 497.7, Max: 497.8, Diff: 0.1, Sum: 1991.0]
[GC Worker End (ms): Min: 160064.7, Avg: 160064.7, Max: 160064.7, Diff: 0.0]
[Code Root Fixup: 0.0 ms]
[Code Root Purge: 0.0 ms]
[Clear CT: 0.0 ms]
[Other: 11.2 ms]
[Evacuation Failure: 11.0 ms]
[Choose CSet: 0.0 ms]
[Ref Proc: 0.1 ms]
[Ref Enq: 0.0 ms]
[Redirty Cards: 0.1 ms]
[Humongous Register: 0.0 ms]
[Humongous Reclaim: 0.0 ms]
[Free CSet: 0.0 ms]
[Eden: 11.0M(51.0M)->0.0B(51.0M) Survivors: 0.0B->0.0B Heap: 1022.1M(1024.0M)->1022.1M(1024.0M)]
[Times: user=1.10 sys=0.34, real=0.51 secs]
[GC pause (G1 Evacuation Pause) (young) (initial-mark), 0.1444584 secs]
[Parallel Time: 144.1 ms, GC Workers: 4]
[GC Worker Start (ms): Min: 160076.1, Avg: 160076.1, Max: 160076.1, Diff: 0.0]
[Ext Root Scanning (ms): Min: 105.2, Avg: 105.8, Max: 106.3, Diff: 1.1, Sum: 423.1]
[Update RS (ms): Min: 1.0, Avg: 1.5, Max: 1.9, Diff: 0.9, Sum: 6.0]
[Processed Buffers: Min: 2, Avg: 2.5, Max: 3, Diff: 1, Sum: 10]
[Scan RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
[Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
[Object Copy (ms): Min: 36.0, Avg: 36.4, Max: 36.9, Diff: 1.0, Sum: 145.5]
[Termination (ms): Min: 0.0, Avg: 0.4, Max: 0.8, Diff: 0.8, Sum: 1.6]
[Termination Attempts: Min: 1, Avg: 1.0, Max: 1, Diff: 0, Sum: 4]
[GC Worker Other (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
[GC Worker Total (ms): Min: 144.1, Avg: 144.1, Max: 144.1, Diff: 0.0, Sum: 576.3]
[GC Worker End (ms): Min: 160220.2, Avg: 160220.2, Max: 160220.2, Diff: 0.0]
[Code Root Fixup: 0.0 ms]
[Code Root Purge: 0.0 ms]
[Clear CT: 0.0 ms]
[Other: 0.3 ms]
[Choose CSet: 0.0 ms]
[Ref Proc: 0.2 ms]
[Ref Enq: 0.0 ms]
[Redirty Cards: 0.0 ms]
[Humongous Register: 0.0 ms]
[Humongous Reclaim: 0.0 ms]
[Free CSet: 0.0 ms]
[Eden: 0.0B(51.0M)->0.0B(51.0M) Survivors: 0.0B->0.0B Heap: 1022.1M(1024.0M)->1022.1M(1024.0M)]
[Times: user=0.56 sys=0.01, real=0.15 secs]
[GC concurrent-root-region-scan-start]
[GC concurrent-root-region-scan-end, 0.0000053 secs]
[GC concurrent-mark-start]
[Full GC (Allocation Failure) 1022M->1022M(1024M), 3.8210984 secs]
[Eden: 0.0B(51.0M)->0.0B(51.0M) Survivors: 0.0B->0.0B Heap: 1022.1M(1024.0M)->1022.0M(1024.0M)], [Metaspace: 3347K->3347K(1056768K)]
[Times: user=5.67 sys=0.03, real=3.82 secs]
[Full GC (Allocation Failure) 1022M->1022M(1024M), 3.7742211 secs]
[Eden: 0.0B(51.0M)->0.0B(51.0M) Survivors: 0.0B->0.0B Heap: 1022.0M(1024.0M)->1022.0M(1024.0M)], [Metaspace: 3347K->3347K(1056768K)]
[Times: user=5.64 sys=0.03, real=3.77 secs]
[GC concurrent-mark-abort]
[GC pause (G1 Evacuation Pause) (young), 0.1590867 secs]
[Parallel Time: 158.8 ms, GC Workers: 4]
[GC Worker Start (ms): Min: 167816.3, Avg: 167816.4, Max: 167816.4, Diff: 0.1]
[Ext Root Scanning (ms): Min: 122.4, Avg: 123.8, Max: 125.6, Diff: 3.2, Sum: 495.1]
[Update RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
[Processed Buffers: Min: 0, Avg: 0.2, Max: 1, Diff: 1, Sum: 1]
[Scan RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
[Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
[Object Copy (ms): Min: 33.0, Avg: 34.8, Max: 36.1, Diff: 3.2, Sum: 139.3]
[Termination (ms): Min: 0.0, Avg: 0.1, Max: 0.1, Diff: 0.1, Sum: 0.3]
[Termination Attempts: Min: 1, Avg: 1.0, Max: 1, Diff: 0, Sum: 4]
[GC Worker Other (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
[GC Worker Total (ms): Min: 158.6, Avg: 158.7, Max: 158.7, Diff: 0.1, Sum: 634.7]
[GC Worker End (ms): Min: 167975.0, Avg: 167975.0, Max: 167975.1, Diff: 0.0]
[Code Root Fixup: 0.0 ms]
[Code Root Purge: 0.0 ms]
[Clear CT: 0.1 ms]
[Other: 0.3 ms]
[Choose CSet: 0.0 ms]
[Ref Proc: 0.1 ms]
[Ref Enq: 0.0 ms]
[Redirty Cards: 0.1 ms]
[Humongous Register: 0.0 ms]
[Humongous Reclaim: 0.0 ms]
[Free CSet: 0.0 ms]
[Eden: 0.0B(51.0M)->0.0B(51.0M) Survivors: 0.0B->0.0B Heap: 1022.0M(1024.0M)->1022.0M(1024.0M)]
[Times: user=0.57 sys=0.01, real=0.16 secs]
[GC pause (G1 Evacuation Pause) (young) (initial-mark), 0.2154171 secs]
[Parallel Time: 215.2 ms, GC Workers: 4]
[GC Worker Start (ms): Min: 167975.6, Avg: 167976.4, Max: 167979.0, Diff: 3.4]
[Ext Root Scanning (ms): Min: 162.4, Avg: 165.3, Max: 167.9, Diff: 5.5, Sum: 661.3]
[Update RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
[Processed Buffers: Min: 0, Avg: 0.2, Max: 1, Diff: 1, Sum: 1]
[Scan RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
[Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
[Object Copy (ms): Min: 46.1, Avg: 48.9, Max: 52.5, Diff: 6.4, Sum: 195.4]
[Termination (ms): Min: 0.0, Avg: 0.1, Max: 0.1, Diff: 0.1, Sum: 0.3]
[Termination Attempts: Min: 1, Avg: 1.0, Max: 1, Diff: 0, Sum: 4]
[GC Worker Other (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
[GC Worker Total (ms): Min: 211.7, Avg: 214.3, Max: 215.1, Diff: 3.4, Sum: 857.1]
[GC Worker End (ms): Min: 168190.7, Avg: 168190.7, Max: 168190.7, Diff: 0.0]
[Code Root Fixup: 0.0 ms]
[Code Root Purge: 0.0 ms]
[Clear CT: 0.0 ms]
[Other: 0.2 ms]
[Choose CSet: 0.0 ms]
[Ref Proc: 0.1 ms]
[Ref Enq: 0.0 ms]
[Redirty Cards: 0.0 ms]
[Humongous Register: 0.0 ms]
[Humongous Reclaim: 0.0 ms]
[Free CSet: 0.0 ms]
[Eden: 0.0B(51.0M)->0.0B(51.0M) Survivors: 0.0B->0.0B Heap: 1022.0M(1024.0M)->1022.0M(1024.0M)]
[Times: user=0.71 sys=0.00, real=0.22 secs]
[GC concurrent-root-region-scan-start]
[GC concurrent-root-region-scan-end, 0.0000065 secs]
[GC concurrent-mark-start]
[Full GC (Allocation Failure) 1022M->400K(8192K), 0.7234020 secs]
[Eden: 0.0B(51.0M)->0.0B(3072.0K) Survivors: 0.0B->0.0B Heap: 1022.0M(1024.0M)->400.6K(8192.0K)], [Metaspace: 3347K->3347K(1056768K)]
[Times: user=1.29 sys=0.09, real=0.72 secs]
Exception in thread “main” java.lang.OutOfMemoryError: Java heap space
at java.lang.Integer.toString(Integer.java:401)
at java.lang.String.valueOf(String.java:3099)
at com.kite.java.StringTest.test1_1(StringTest.java:26)
at com.kite.java.StringTest.main(StringTest.java:14)
[GC concurrent-mark-abort]
Heap
garbage-first heap total 8192K, used 400K [0x0000000780000000, 0x0000000780100040, 0x00000007c0000000)
region size 1024K, 1 young (1024K), 0 survivors (0K)
Metaspace used 3377K, capacity 4564K, committed 4864K, reserved 1056768K
class space used 372K, capacity 388K, committed 512K, reserved 1048576K

最終添加16509952(1651萬)次左右(因1024 * 1024循環(huán)才會輸出一次,故近似)最終報錯內(nèi)存不足,因和第一個實驗不同,本次為避免重復(fù)文本,故每次循環(huán)使用的文本均不同,故所占內(nèi)存較大。

放到Xmx限制可以存放更多內(nèi)存(這里不再實驗),可見字符串常量池也沒有內(nèi)存限制。

實驗3和實驗4-字符串常量池會復(fù)用內(nèi)存

實驗3

可用實驗1數(shù)據(jù)。

實驗4

public static void main(String[] args) throws InterruptedException {
        System.out.println("--begin...");
        String[] result = test1_1();
        System.out.println("--end");
        System.out.println("--gc...");
        System.gc();
        System.out.println("--gc end");
    }
    private static String[] test1_1() {
        //jvm:-Xmx1G -XX:+PrintGCDetails -XX:+UseG1GC
        String[] array = new String[35 * 1024 * 1024];
        //37335040(3700萬)次循環(huán)
        for (int i = 0; i < 35 * 1024 * 1024; i++) {
            String str1 = String.valueOf("A").intern();
            array[i] = str1;
            if (i % 1024 * 1024 == 0) {
                System.out.println("now i=" + i);
            }
        }
        return array;
    }

最終輸出:

now i=36696064
now i=36697088
now i=36698112
now i=36699136
–end
–gc…
[Full GC (System.gc()) 147M->140M(269M), 0.5767602 secs]
[Eden: 7168.0K(12.0M)->0.0B(15.0M) Survivors: 1024.0K->0.0B Heap: 147.0M(269.0M)->140.4M(269.0M)], [Metaspace: 3346K->3346K(1056768K)]
[Times: user=0.54 sys=0.01, real=0.58 secs]
–gc end
Heap
garbage-first heap total 275456K, used 143778K [0x0000000780000000, 0x0000000780100868, 0x00000007c0000000)
region size 1024K, 1 young (1024K), 0 survivors (0K)
Metaspace used 3352K, capacity 4564K, committed 4864K, reserved 1056768K
class space used 369K, capacity 388K, committed 512K, reserved 1048576K

假設(shè)去掉循環(huán),只是初始化數(shù)組:

    public static void main(String[] args) throws InterruptedException {
        System.out.println("--begin...");
        String[] result = test1_1();
        System.out.println("--end");
        System.out.println("--gc...");
        System.gc();
        System.out.println("--gc end");
    }
    private static String[] test1_1() {
        //jvm:-Xmx1G -XX:+PrintGCDetails -XX:+UseG1GC
        String[] array = new String[35 * 1024 * 1024];
//        //37335040(3700萬)次循環(huán)
//        for (int i = 0; i < 35 * 1024 * 1024; i++) {
//            String str1 = String.valueOf("A").intern();
//            array[i] = str1;
//            if (i % 1024 * 1024 == 0) {
//                System.out.println("now i=" + i);
//            }
//        }
        return array;
    }

最后輸出:

[Full GC (System.gc()) 140M->140M(269M), 0.3415958 secs]
[Eden: 1024.0K(14.0M)->0.0B(15.0M) Survivors: 1024.0K->0.0B Heap: 140.8M(269.0M)->140.4M(269.0M)], [Metaspace: 3308K->3308K(1056768K)]
[Times: user=0.33 sys=0.00, real=0.35 secs]
–gc end
Heap
garbage-first heap total 275456K, used 143773K [0x0000000780000000, 0x0000000780100868, 0x00000007c0000000)
region size 1024K, 1 young (1024K), 0 survivors (0K)
Metaspace used 3314K, capacity 4564K, committed 4864K, reserved 1056768K
class space used 369K, capacity 388K, committed 512K, reserved 1048576K

無論有無添加字符串進數(shù)組,GC后只使用了140M內(nèi)存。而對比實驗3,占用了980M內(nèi)存,可見字符串常量池是復(fù)用內(nèi)存的。

實驗5和實驗6-字符串常量池-釋放內(nèi)存

實驗5-常量池內(nèi)存大小超過jvm

結(jié)合實驗2數(shù)據(jù),將16509952次循環(huán)數(shù)據(jù)分2次放入內(nèi)存中:

public static void main(String[] args) throws InterruptedException {
        System.out.println("--begin...");
        String[][] result = test1_1();
        System.out.println("--end");
        System.out.println("--gc...");
        System.gc();
        System.out.println("--gc end");
    }
    private static String[][] test1_1() {
        String[][] result = new String[2][];
        //jvm:-Xmx1G -XX:+PrintGCDetails -XX:+UseG1GC
        //16509952(1651萬)一半次循環(huán)
        String[] array1 = new String[16509952 / 2];
        for (int i = 0; i < 16509952 / 2; i++) {
            String str1 = String.valueOf(i).intern();
            array1[i] = str1;
            if (i % 1024 * 1024 == 0) {
                System.out.println("now i=" + i);
            }
        }
        result[0] = array1;
        String[] array2 = new String[16509952 / 2];
        System.out.println((16509952 / 2) + "次已經(jīng)添加完畢,另一半開始添加:");
        //16509952 (1651萬)另一半次循環(huán)
        for (int i = 16509952 / 2; i < 16509952; i++) {
            String str1 = String.valueOf(i).intern();
            array2[i - 16509952 / 2] = str1;
            if (i % 1024 * 1024 == 0) {
                System.out.println("now i=" + i);
            }
        }
        result[1] = array2;
        return result;
    }

最后輸出:

now i=16506880
now i=16507904
now i=16508928
–end
–gc…
[Full GC (System.gc()) 970M->945M(1024M), 4.4443937 secs]
[Eden: 12.0M(44.0M)->0.0B(51.0M) Survivors: 6144.0K->0.0B Heap: 971.0M(1009.0M)->945.0M(1024.0M)], [Metaspace: 3348K->3348K(1056768K)]
[Times: user=6.17 sys=0.06, real=4.44 secs]
[GC concurrent-mark-abort]
–gc end
Heap
garbage-first heap total 1048576K, used 967702K [0x0000000780000000, 0x0000000780102000, 0x00000007c0000000)
region size 1024K, 1 young (1024K), 0 survivors (0K)
Metaspace used 3354K, capacity 4564K, committed 4864K, reserved 1056768K
class space used 369K, capacity 388K, committed 512K, reserved 1048576K

共占用內(nèi)存945M。

實驗6-常量池內(nèi)存大小超過jvm-字符串常量池-釋放內(nèi)存

在第一半添加進入后,不加入到最后返回的結(jié)果中(即沒有引用可以被回收):

public static void main(String[] args) throws InterruptedException {
        System.out.println("--begin...");
        String[][] result = test1_1();
        System.out.println("--end");
        System.out.println("--gc...");
        System.gc();
        System.out.println("--gc end");
    }
    private static String[][] test1_1() {
        String[][] result = new String[2][];
        //jvm:-Xmx1G -XX:+PrintGCDetails -XX:+UseG1GC
        //16509952(1651萬)一半次循環(huán)
        String[] array1 = new String[16509952 / 2];
        for (int i = 0; i < 16509952 / 2; i++) {
            String str1 = String.valueOf(i).intern();
            array1[i] = str1;
            if (i % 1024 * 1024 == 0) {
                System.out.println("now i=" + i);
            }
        }
//        result[0] = array1;
        String[] array2 = new String[16509952 / 2];
        System.out.println((16509952 / 2) + "次已經(jīng)添加完畢,另一半開始添加:");
        //16509952 (1651萬)另一半次循環(huán)
        for (int i = 16509952 / 2; i < 16509952; i++) {
            String str1 = String.valueOf(i).intern();
            array2[i - 16509952 / 2] = str1;
            if (i % 1024 * 1024 == 0) {
                System.out.println("now i=" + i);
            }
        }
        result[1] = array2;
        return result;
    }

最后輸出:

now i=16506880
now i=16507904
now i=16508928
–end
–gc…
[Full GC (System.gc()) 522M->472M(864M), 2.5913440 secs]
[Eden: 36.0M(37.0M)->0.0B(43.0M) Survivors: 6144.0K->0.0B Heap: 523.0M(864.0M)->472.8M(864.0M)], [Metaspace: 3348K->3348K(1056768K)]
[Times: user=3.74 sys=0.02, real=2.59 secs]
–gc end
Heap
garbage-first heap total 884736K, used 484110K [0x0000000780000000, 0x0000000780101b00, 0x00000007c0000000)
region size 1024K, 1 young (1024K), 0 survivors (0K)
Metaspace used 3354K, capacity 4564K, committed 4864K, reserved 1056768K
class space used 369K, capacity 388K, committed 512K, reserved 1048576K

可見最后只用了472M,說明之前添加的已經(jīng)被回收了。

總結(jié)

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • SpringMVC源碼解讀之 HandlerMapping - AbstractDetectingUrlHandlerMapping系列初始化

    SpringMVC源碼解讀之 HandlerMapping - AbstractDetectingUrlHandlerM

    這篇文章主要介紹了SpringMVC源碼解讀之 HandlerMapping - AbstractDetectingUrlHandlerMapping系列初始化的相關(guān)資料,需要的朋友可以參考下
    2016-02-02
  • java新增關(guān)聯(lián)的三張表,每張表要求都插入集合,代碼實現(xiàn)方式

    java新增關(guān)聯(lián)的三張表,每張表要求都插入集合,代碼實現(xiàn)方式

    這篇文章主要介紹了java新增關(guān)聯(lián)的三張表,每張表要求都插入集合,代碼實現(xiàn)方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-12-12
  • maven?repository詳解

    maven?repository詳解

    這篇文章主要介紹了maven?repository的相關(guān)知識,本文通過示例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-05-05
  • IntelliJ IDEA安裝插件阿里巴巴Java開發(fā)手冊(Alibaba Java Coding Guidelines)

    IntelliJ IDEA安裝插件阿里巴巴Java開發(fā)手冊(Alibaba Java Coding Guidelines

    這篇文章主要介紹了IntelliJ IDEA安裝插件阿里巴巴Java開發(fā)手冊(Alibaba Java Coding Guidelines),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-05-05
  • Java GZIP壓縮與解壓縮代碼實例

    Java GZIP壓縮與解壓縮代碼實例

    這篇文章主要介紹了Java GZIP壓縮與解壓縮代碼實例,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-01-01
  • 淺談SpringSecurity注解與AOP切面執(zhí)行順序

    淺談SpringSecurity注解與AOP切面執(zhí)行順序

    這篇文章主要介紹了淺談SpringSecurity注解與AOP切面執(zhí)行順序,引入Spring Security后,在Controller的方法中會出現(xiàn)Spring Security的方法注解與AOP同時存在的問題,這是就會設(shè)計順序問題,需要的朋友可以參考下
    2023-10-10
  • java枚舉類的屬性、方法和構(gòu)造方法應(yīng)用實戰(zhàn)

    java枚舉類的屬性、方法和構(gòu)造方法應(yīng)用實戰(zhàn)

    這篇文章主要介紹了java枚舉類的屬性、方法和構(gòu)造方法應(yīng)用,結(jié)合實例形式分析了java枚舉類的定義、構(gòu)造及相關(guān)應(yīng)用操作技巧,需要的朋友可以參考下
    2019-08-08
  • 一篇帶你解析入門LongAdder源碼

    一篇帶你解析入門LongAdder源碼

    LongAdder類是JDK1.8新增的一個原子性操作類。AtomicLong通過CAS算法提供了非阻塞的原子性操作,因為非常搞并發(fā)的請求下AtomicLong的性能是不能讓人接受的
    2021-06-06
  • 詳解Java數(shù)組的四種拷貝方式

    詳解Java數(shù)組的四種拷貝方式

    Java數(shù)組一共有四種拷貝方式: for循環(huán)、copyof/copyOfRange、arraycopy和clone。本文將為大家詳細介紹一下這四種方式,感興趣的可以了解一下
    2022-02-02
  • 使用Logback設(shè)置日志級別

    使用Logback設(shè)置日志級別

    這篇文章主要介紹了使用Logback設(shè)置日志級別的操作,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-07-07

最新評論