What is the best way to clean up an Object in Java?

后端 未结 9 1920
悲&欢浪女
悲&欢浪女 2021-01-01 14:05

We don\'t have any destructor in Java as we have in C++.

Q1. How should we clean up any Object in java.

Q2. Is there any a

9条回答
  •  走了就别回头了
    2021-01-01 14:41

    You could also add a shutdown hook to your program, if your program is shutting down too:

    //add shutdown hook
    Runtime.getRuntime().addShutdownHook(new Thread() {
        public void run() {
            ThirdPartyTerminate();
        }
    });
    

提交回复
热议问题