When will the new String() object in memory gets cleared after invoking intern() method

后端 未结 2 2144
天命终不由人
天命终不由人 2021-01-06 01:39
List list = new ArrayList<>();
for (int i = 0; i < 1000; i++)
{
    StringBuilder sb = new StringBuilder();
    String string = sb.toString();         


        
2条回答
  •  感情败类
    2021-01-06 01:48

    You can open JMC and check for GC under Memory tab inside MBean Server of the particular JVM when it performed and how much did it cleared. Still, there is no fixed guarantee of the time when it would be called. You can initiate GC under Diagnostic Commands on a specific JVM.

    Hope it helps.

提交回复
热议问题