I wrote such a piece of code:
public class TestClass {
private static List<String> stringList = new ArrayList<>();
long num;
public void testHighLoad() {
stringList.clear();
for (int i = 0; i < num; i++) {
String string = getRandomString(10000);
stringList.add(string);
}
}
public void setNum (int num) {
this.num = num;
}
}
And I can call it like this to make it cost high memories:
testClass.setNum(500000);
testClass.testHighLoad();
But then if I call it in this way, it cannot release the memory:
testClass.setNum(0);
testClass.testHighLoad();