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 An Application By Using Java Program?
- What How The Step For Make Library Management?
- In Which Process We Can Start Java?
- Define The Concept Of Java Byte Code?
- How To Run Remote Method Invocation In More Machine?
- How To Run Java Remote Method Invocation In More Machine?
- How To Make A Java Program That Will Ask The User To Input A Number And Display All The Even Number And The Sum Of All Even Numbers Based On The Inputted/ Given Numbers?
- Is A Static Variable An Instance?
- How To Compile And Run Java Package?
- What Does Literati-on Mean?
- What Is Abstract Class In Details?
- What Is Meant By Remote Method Invocation In Java?
- What Is Meant By Package In Java?
- What Is Meant By Servlet In Java?
- When Was Java Released?
- What Is Latest Technologies In Java?
- Write A Program Using Do…..while Loop To Calculate And Print The First M Fibonacci Numbers?
- What Is The Difference Between Reference &instance Variable?
- Why Java Is Slow?
- What Is The Drawback Of Ms Access?
- What Is Replaced In Place Of Pointers In Java?
- What Replaces Pointers In Java?
- How Many Types We Create Object In Java?
- I Signed Up Promo Code 505124 For 12 Months My Bill Said For 6 Months Who Fix This Error?
- What Is The Expansion Of Java?
- 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?
- What Is The Similarities Between C++ Language And Java 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?

New Comment - Comments are editable for 5 min.