+ 3
Lost String Object
When we initialize a string by assigning it some value and then later when we try to manipulate the same string by concatenating or replacing we say that the new string is assigned to a newly created string object by the JVM but since we did not create a reference, it is lost. My question is, does garbage collector takes care of the lost objects? Or something else happens behind the scene. For example- String str = "hello"; str.concat("world"); What happens to the lost object which contains hello world.
7 ответов
+ 1
"Hello world" also exist in string pool until the garbage collection takes place.. i think.
+ 1
Yes.
Garbage collection is takes place when no more variables point to that string, it is deallocated and eventually deleted from memory to free up space. and its automatic..
+ 1
Jaya krishna
Denise Roßberg
Thanks for helping.
0
Jaya krishna So garbage collector clears that memory space?
0
hhj