Using JDK 1.8 and VisualVM, I saw a string's retained size is 0. According to this article, this means the memory allocated to the string is 0. Does this mean the string has already been GC? If if was already been GC, why does it still display? If not, What does retained size=0 mean? Does it mean "If JVM GC this string, it can only get 0 KB of memory free"?
The example code is:
public class Main {
private static final Logger LOGGER = Logger.getLogger(Main.class.getName());
private static ExecutorService executorService = Executors.newFixedThreadPool(3);
public static void main(String[] args) throws InterruptedException {
AAAAAAAA a = new AAAAAAAA();
a.setString();
Thread.sleep(55555555); // I dump it when it's asleep.
}
}
class AAAAAAAA {
String string = "wawawawa";
public void setString() {
string = "hahahahaha";
}
}