You have the option of including a method finalize() in a class definition. This method is called automatically by Java before an object is finally destroyed and the space it occupies in memory is released. In practice this may be some time after the object is inaccessible in your program. When an object goes out of scope, it is dead as far as your program is concerned, but the Java Virtual Machine may not get around to disposing of the remains until later. When it does, it calls the finalize() method for the object.
protected void finalize() {
// Your clean-up code...
}
I modified the classes from "our first project" to demonstrate it. Click
here to download the updated classes.
No comments:
Post a Comment