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

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

python - How to remove the Xframe Options header in django? -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -