After making m1 = null m1 becomes eligible for garbage collection. So when we call garbage collector the first time, Garbage Collector will call finalize() method on m1 before destroying it.
The finalize method will print "Finalise" here but in finalize method we are again referencing the same object by m which makes it no longer eligible for garbage collection. Hence the garbage collector will not destroy the object.
Now again after making m = null, we are making it again eligible for garbage collection. Since on this object, finalize() method is already called, so now Garbage Collector will destroy it without calling finalize() method again.
• • •
Missing some Tweet in this thread? You can try to
force a refresh
Confused about implementing data structures in real problems?
See some real-world examples of the Data structure "Array" today 👇
A thread 🧵
🔸A parking lot is an example of an array with each index of the array storing whether a car is present or not. Or it may be used for some other functionality.
Want to become an Android developer or start your journey with Android development but have not started yet?
Let me help you create your first Android app to kick off your Android journey.
Work with me to the end of the thread 🧵🧵
First, download Android Studio on your PC through this link and complete the setup and wait for all indexing and initial build to finish (might take time so keep patience) developer.android.com/studio
🔸Click on create new Project
🔸Select Empty Activity
🔸Click on next