esolve
V2EX  ›  问与答

Java 中 interned 字符串为何那么占内存?

  •  
  •   esolve · Oct 23, 2017 · 2355 views
    This topic created in 3300 days ago, the information mentioned may be changed or developed.

    用 jmap -heap 测了一下一个 java 程序,结果说:

    24518 interned Strings occupying 3075472 bytes.
    

    平均每个 string 占 125 个字节

    这很奇怪啊,大部分程序里的 string 哪有这么大

    这是怎么回事?

    6 replies  •  2017-10-23 20:19:24 +08:00
    zts1993
    zts1993
    Oct 23, 2017
    1
    这个问题得先提供一下 JDK 版本
    esolve
    esolve
    OP
    Oct 23, 2017
    2
    @zts1993 jdk8
    zts1993
    zts1993
    Oct 23, 2017
    3
    平均 string 30 上下?
    sagaxu
    sagaxu
    Oct 23, 2017
    4
    用阿里的 fastjson 了吗?
    esolve
    esolve
    OP
    Oct 23, 2017
    5
    @sagaxu 嗯
    esolve
    esolve
    OP
    Oct 23, 2017
    6
    @zts1993 30 ?啥意思?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2774 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 13:25 · PVG 21:25 · LAX 05:25 · JFK 08:25
    ♥ Do have faith in what you're doing.