Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

gc

 
peter kens
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am confused with finalize() chaining given in Mughals page 253, can you anyone give me simple example of finalize() chaining
Thank you very much
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So.... Constructor's are impliclitly chained -- when you create a constructor, if you don't specifically call super() or this() -- then super() will implicitly be called. (If you need more information about this --- check out page 192 in Mughal's)
However, Finalizers are not implicitly chained. Because of this -- you "should explicitly call the finalizer in its super class as its last action." -- that way whatever things the superclass cleans up during its finalizer method, will get done for the subclass as well.
Does that help? What exactly are you confused about?
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Jess said - you finalizers don't chain implicitly like constructors do. When you instantiate an object, the constructor of that class, along with all of its superclasses is invoked. This is not true when it comes to finalization.
It is not required that a superclass be finalized prior to a subclass in the way that a superclass must be initialized prior to a subclass. Thus, there is no implicit invocation of the superclass' finalization method.
It is good practive, however, to invoke it yourself, as Jess mentioned.
Corey
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic