Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

finalize method

 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Programmers are advised not to depend on finalize method being called by the JVM.
The EJB spec says that a bean class should not overide the method at all.
I think this method should be put into a trash bin. Why should we have the method when it is of no use?
 
Ouaknin lionel
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
legacy ?
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please explain more?
 
Jason Davies
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The finalize() method is sometimes used to free memory allocated by native methods - memory that wouldn't be freed by the garbage collector.
They may also be used to prevent sloppy use of your class by ensuring non-memory finite resources such as file handles or sockets are released.
See this related article on JavaWorld: http://www.javaworld.com/javaworld/jw-06-1998/jw-06-techniques_p.html
Hope that helps,
--Jase
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JVM is not required to call the finalize method. What happpens then?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic