String
String
When the string object is created with the help of new keyword then one object is
created in HEAP MEMORY and another object id created in SCP (String Constant Poll)
area.
Reference of object which is created in HEAP MEMORY have reference variable but
reference of object in SCP does not have.
When the object in HEAP MEMORY does not have reference variable then this object
will be destroyed by GARBAGE COLLECTOR. Man this object will be destroyed by the
JVM.
But JVM does not destroyed the object which does not have reference variable in
SCP. Because internally JVM maintain the reference variable for the object created
in SCP.