memory - How to write a piece of java code that will consume lots of memories and the memories can be released if needed -
i wrote such piece of code:
public class testclass { private static list<string> stringlist = new arraylist<>(); long num; public void testhighload() { stringlist.clear(); (int = 0; < num; i++) { string string = getrandomstring(10000); stringlist.add(string); } } public void setnum (int num) { this.num = num; } }
and can call make cost high memories:
testclass.setnum(500000);
testclass.testhighload();
but if call in way, cannot release memory:
testclass.setnum(0);
testclass.testhighload();
Comments
Post a Comment