|
|
|
|||
|
Writing a finalize MethodWhen all references to an object are dropped, the object is no longer required and becomes eligible for garbage collection. Before an object is garbage collected, the runtime system calls itsfinalize
method to release system resources
such as open files or open sockets before the
object is collected.
Your class can provide for its finalization simply by defining and
implementing a Theprotected void finalize() throws Throwable Stack class creates a Vector
when it's created. To be complete and well-behaved,
the Stack class should release its reference
to the Vector. Here's the finalize
method for the Stack class:
The finalize method is declared in the Object
class. As a result, when you write a finalize
method for your class,
you are overriding the one in your superclass.
Overriding Methods
talks more about how to override methods.
The last line of | |||
|