What if Size of String Pool Exceeds?

前端 未结 2 1975
别那么骄傲
别那么骄傲 2021-01-04 13:01

In Java,

String literals in String Constant Pool are not garbage collected, since they are referenced from Table of references which is created by instance of runti

2条回答
  •  鱼传尺愫
    2021-01-04 13:41

    String literals can be collected when they are no longer needed. Usually this is not a problem if they appear in classes because there are other limits you are likely to reach if you attempt to load lots of classes e.g. Maximum Perm Gen.

    Generally speaking, developers are smart enough not to over use the string literal pool and instead using databases or file to load the bulk of their data if its a non trivial size.

    You can introduce a problem if you use String.intern() a lot in an attempt to optimise the space of your system. String.intern() is not free and becomes increasingly expensive if you add a large number (millions) of string into it. If this is a performance problem, it should be reasonably obvious to the developer when it is.

提交回复
热议问题