As it can be seen in the following minimal code, I want when the JAVA object finished, the allocated object in test variable be unallocated. What can I do to unallocate this object?
I used null
and system.gc
, but they don't work to unallocate the object.
package chatclient;
/**
*
* @author root
*/
import java.io.IOException;
public class ChatClient {
private void run() throws IOException {
long test[]=new long[10000000];
test[10000]=100;
// Process all messages from server, according to the protocol.
test=null;
System.gc();
}
@Override
protected void finalize() throws Throwable {
super.finalize(); //To change body of generated methods, choose Tools | Templates.
}
/**
* Runs the client as an application with a closeable frame.
*/
public static void main(String[] args) throws Exception {
while(true){
ChatClient client = new ChatClient();
client.run();
}
}
}