[Solved] String object creation in loop [closed]


Your code is going to loop 1001 times, thus creating 1001 independent String-objects. s is a local variable inside the loop, thus the garbage collector is going to free the memory occupied by these no longer referenced instances as soon as the system needs the memory. Thus, I would not expect any memory issues.

As stated by Trengot there will also be one additional object created for the String-pool. If you consider that it will total to a creation of 1002 String-objects.

solved String object creation in loop [closed]