Lecture 11 - Garbage Collection

Lecture 11 - Garbage Collection - The finalize Method •...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Method Overloading Where 2 or more methods have the same name, but different signatures o Signature: the method name plus the parameter list The return type is not part of the signature o Allows you to give the same name to related methods o The compiler uses signature matching to determine which method to call Garbage Collection Runs as low-priority thread in the JVM An object may eventually be garbage collected once all references to the object are eliminated. o Done at the GC’s discretion o You can usually force garbage collection with: System.gc();
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: The finalize() Method • Is invoked by the system just before an object is garbage collected o You can’t call finalize() directly • Useful for : o Reclaiming resources Eg: closing opened files, closing socket connections o General cleanup Eg: resetting a class variable o Is inherited from the superclass Object o Form: protected void finalize() throw Throwable { super.finalize(); // custom code goes here o Eg: keeping track of the number of objects currently active for a class READING AND EXERCISES CHAPTERS 4 AND 5...
View Full Document

{[ snackBarMessage ]}

Page1 / 2

Lecture 11 - Garbage Collection - The finalize Method •...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online