2 Answers - Sort by: Date | Rating
Java's garbage collection mechanism automatically detects when there are no further references to an object and reclaims the memory associated with it. There is no need to explicitly clean up memory as is done with destructors in the C++ language.
If your object has some resources associated with it, however, and you feel the need to process these in some way before your object is destroyed you can override the finalize() method in your class. All Java classes have a finalize() method inherited from the Object class. Normally, this it is not necessary to override it.
In some cases, as, for example, if the object opens files and you want to make sure they are properly closed before the object itself is destroyed, you could implement the finalize() method. The garbage collector will always call it before destroying your object. It is considered good form to call super.finalize() after your own code is done so that superclasses can perform any finalization of their own.
If your object has some resources associated with it, however, and you feel the need to process these in some way before your object is destroyed you can override the finalize() method in your class. All Java classes have a finalize() method inherited from the Object class. Normally, this it is not necessary to override it.
In some cases, as, for example, if the object opens files and you want to make sure they are properly closed before the object itself is destroyed, you could implement the finalize() method. The garbage collector will always call it before destroying your object. It is considered good form to call super.finalize() after your own code is done so that superclasses can perform any finalization of their own.
0
0
- How To Make Your Phone Java Supported?
- What Are The Service In Rmi?
- I'm Having A Problem With The Error Code 25099 Unzipping Core File Failed.I've Tried Everything I Can Think Of. ?
- How Do I Workaround Error 25099?
- How Do I Install Java When I Keep Getting This Unzipping Core Files?
- How To Wright A Java Programme After Setting Path For It?
- If There Is One Class Template Which Has One Static Member Variable That Static Variable Will Belong To?
- How To Install Java On A I465?
- How To Load Java On Lg Env2?
- How Are Lists Implemented In Java?
- How To Write Small Program That Printout The Even Integers From 2 To 100 Using A Do While Loop?
- What Is The Theme For Math Fair 2009?
- What Is The Theme Of Math Month?
- How To Create A Batch File To Execute MS Word Application?
- Why Are Read Jvm In Byte Code?
- What Is The Function Of Final?
- How To Create A Diamond In For Loop In Java Using *?
- Public Static Void Main(string A[]) I Know Why Use Static Keyword?
- Do Stores Accept Blank Checks?
- What Good Qualities Of A Java Class?
- How Can I Compile My Own Rmi Package?
- I Want To Run A Basic Program In Unical, Engneering Program. How Will I Go About It?
- Balance Used Could Be Read To 0.01 Gram, What Percentage Error Might You Expect When Weighing A 10.00 Gram Object?
- How To Fix Java Errors On Cell Phone This Is What It Says Null Pointer Java/lang/null Pointer Exception It Says The Above When I Try To Connect To The Internet?
- What Is The Difference Between C Language And Java Language?
- What Are The Advantage Of Using Java Language?
- What Is The Difference Between C++ Language And Java Language?
- What Is The Similarities Between C Language And Java Language?
- Is Java The Best Programming Language?
- Is Multiple Inheritance Possible In Java Language Or Not?
- What Do You Mean By Memory Leakage In Java Language?
- Which Is The Best Programming Language, JAVA Or .NET?
- What Is The Difference Between Java And .net Language?
- What Is The Major Difference Between Java Language And C Language?
- Is Java Purely An Object Oriented Language?
- Why Java Is Called Both Compiled And Interpreted Language?
- Could You Tell Me Some Project Titles That Can Be Done With Java Or .net Language?

New Comment - Comments are editable for 5 min.