Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
GC 是否在运行时常量池上运行?
如果是,什么时候?如果不是,如果字符串池中满是字符串文字会怎样?
我做了谷歌,但在我的机器上尝试了这个问题的任何相关内容。
你的问题太低级了,因为它可以简单地通过观察字符串文字总是可以访问的来解决,从它出现的类中引用。
自 Java 6 以来,常量池恰好受到垃圾回收的影响,当时它被移至常规堆。仅当您的代码使用许多String.intern()调用时才会发挥作用,这些调用可以将字符串添加到常量池中。
String.intern()