• Post Reply Bookmark Topic Watch Topic
  • New Topic

About the finalize() method  RSS feed

 
Vaibhav Manwatkar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Friends...

Again a doubt I have regarding the finalize().. as it is decleared protected in the base class, I am not able to write that method..

Can any body give me a simple classes example through which I will get the idea.. or atleast tell me the syntax to write.. bye.
 
Horatio Westock
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Vaibhav Manwatkar:
Again a doubt I have regarding the finalize().. as it is decleared protected in the base class, I am not able to write that method..


Really?

Have a look at this.
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Vaibhav -

Why do you want to override finalize()?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The finalize method is protected in Object, so it can be overridden in other classes if needed.

As explained in the API documentation for Object, "the usual purpose of finalize ... is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection..."
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know why it's usually overridden, I was just curious why the original poster wanted to override it...
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeff Bosch:
I know why it's usually overridden, I was just curious why the original poster wanted to override it...

Yes, my post was directed to the original poster. Sorry for the confusion.
 
Ashish Chopra
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem might not be in the finalize method, but the access level that u may be giving it. If you override the finalize method, then its access modifier must be higher than protected.

If your idea is to guarantee garbage collection by overriding the finalize method, let me tell you that it can't be done. There are no guarantees attached with the garbage collector. For more, see this: Truth about GC
[ April 05, 2005: Message edited by: Ashish Chopra ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!