0

In general in any project we use lot of string's , as

String name="John"; ...etc   

But According to JVM String literal cannot be GC'd
even though we are not having use with name after sometime ie

name = null;  

that object cannot be GC'd
Why it is Designed in that way which may lead to out of memory Problems

LMK
  • 2,882
  • 5
  • 28
  • 52
  • please provide the source of _According to JVM_ – Oleg Mikheev May 30 '14 at 04:48
  • JVM optimzes stringm usage using stringpool. It will be Gc'ed but only when it is absolutely necessary, else it will be maintained in StringPool and if the same string is used for some other variable assignment, instead of creating a new string it will use the same from the string pool. +1Oleg – ganaraj May 30 '14 at 05:19
  • Your claimed requirement does not appear in either the current [Java Language Specification](http://docs.oracle.com/javase/specs/jls/se8/jls8.pdf) or the current [Java Virtual Machine Specification](http://docs.oracle.com/javase/specs/jvms/se8/jvms8.pdf). – user207421 May 30 '14 at 06:14

0 Answers0