The Artima Developer Community
Sponsored Link

Java Answers Forum
Destructor

3 replies on 1 page. Most recent reply: Jun 23, 2002 10:58 PM by Matt Gerrans

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Mohd Hafizzul b. Mohd Salleh

Posts: 1
Nickname: pijo
Registered: Jun, 2002

Destructor Posted: Jun 22, 2002 9:52 PM
Reply to this message Reply
Advertisement
I'm a beginner
How to create a destructor for object in Java..?


Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: Destructor Posted: Jun 22, 2002 11:38 PM
Reply to this message Reply
Welcome to Java. There are no destructors! There are finalizers, but you shouldn't think of them as destructors, since they are not guaranteed to ever be called (even is you do a System.gc()). If your class must free up some resource, then it should have a close() method that does this. You can use the finalizer to check that close() was called and display an error if the object was not properly closed before being collected, but this just is a form of spot-checking. Also, you would probably not want this in your released code, or you'd want it to be doing the check only when a debugging flag was set.

Thomas SMETS

Posts: 307
Nickname: tsmets
Registered: Apr, 2002

Re: Destructor Posted: Jun 23, 2002 3:23 PM
Reply to this message Reply
Matt,

though you are definitively right (like always ;-)), doing a System.runFinalization(); helps a great deal to have most finalizers run.
You also have System.runFinalizersOnExit (true);

but as you wrote it .. There is no garanty it will ever be called.

Thomas SMETS - Brussels

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: Destructor Posted: Jun 23, 2002 10:58 PM
Reply to this message Reply
Hey Thomas,

Welcome back -- where have you been lately?

You know, I replied to a couple of the emails you sent me, but they always bounce; your return email address doesn't have anything obvious like "no-spam" embedded in it, so I don't know what the cause is...

Flat View: This topic has 3 replies on 1 page
Topic: Upload file directory Previous Topic   Next Topic Topic: what am i doing wrong

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use