Can java String literals like "abc"
be garbage collected?. If yes, how can we programatially prove that they are GCed?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Yes, post Java7, String literals can be garbage collected if the class loader which loaded it gets garbage collected and there are no references to the string literal.
Note : In Java -8, you will have to call GC twice in order to ensure that ClassLoaders get GCed (Metaspace.. pfff..Using a different GC won't help).
An easy way to proof it, is using a profiler. A profiler gives you the ability to see all objects that are in memory of the application.