How to ensure finalize() is always called (Thinking in Java exercise)

前端 未结 5 846
情深已故
情深已故 2020-12-10 03:51

I\'m slowly working through Bruce Eckel\'s Thinking in Java 4th edition, and the following problem has me stumped:

Create a class with a fina

5条回答
  •  自闭症患者
    2020-12-10 04:12

    A call to garabage collecter (System.gc()) method suggests that the Java Virtual Machine expend effort toward recycling unused objects in order to make the memory they currently occupy available for quick reuse (i.e its just a suggestion to the jvm, and does not bind it to perform the action then and there, it may or may not do the same). When control returns from the method call, the Java Virtual Machine has made a best effort to reclaim space from all discarded objects. finalize() is called by the garbage collector on an object when garbage collection determines that there are no more references to the object

提交回复
热议问题