| Author |
Why Donot finalize method run?
|
Gowher Naik
Ranch Hand
Joined: Feb 07, 2005
Posts: 643
|
|
In above code the finalize method donot run i am not able to understand why. Thanks
|
 |
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
|
|
|
You have implemented finalize in your Test class. You do not create an instance of your Test class. So no instance of the Test class needs to be garbage collected (or rather, is eligible for garbage collection)
|
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
|
 |
Gowher Naik
Ranch Hand
Joined: Feb 07, 2005
Posts: 643
|
|
|
But there are Integer objects inside for loop which should be garbage collected.
|
 |
Awais Sheikh
Ranch Hand
Joined: Jun 07, 2006
Posts: 48
|
|
Hello, Finalize method is called when object of a class is created and completes its work, but remember finalize method should in the class whose garbage it has to be collect. In your code you implemented in the test class, but no where object of Test class is created so this finalize method will not called by gc. new Interger is calling finalize method of Integer class not Test class. Try the code below hope it will clear you. Thanks
|
 |
Gowher Naik
Ranch Hand
Joined: Feb 07, 2005
Posts: 643
|
|
Thanks Awais Sheikh Now i understood it.
|
 |
 |
|
|
subject: Why Donot finalize method run?
|
|
|