There is no direct and immediate way to free memory in java. You might try to persuade the garbage collector to take away some object using the well known:
Object obj = new Object();
// use obj
obj = null;
System.gc();
but there is no guarantee that this will actually free memory immediately.
While this applies to heap memory, stack allocated items can only be freed when the function returns.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…