Article View: aus.computers.java
Article #434Re: How to cleanup when a class is destroyed ?
From: Benjamin Johnston
Date: Thu, 12 Oct 2000 00:00
Date: Thu, 12 Oct 2000 00:00
32 lines
1791 bytes
1791 bytes
> I agree Stephen. > > But shouldn't the garbage collector cleanup when the application is > completed ? > > I thought that when the app is completed, the garbage collector would clean > up the the instantiated class1, hence calling the finalize method. > > If that isn't the case, how do you arrange for an instantiated class to > close ports it has opend etc, when the application is completed ? > > This is puzzling ! Take a look at the JavaDocs for; System.runFinalizersOnExit(boolean); And Object.finalize(); But, keep in mind that most of the time you'll find that you won't/shouldn't need to do any finalization at all (its more of a C++ thing)... To quote "Java 2 Performance and Idiom Guide"; For many resources (threads, files, sockets and so on) it will be usually be completely obvious when they can be released or closed. The finalize method, on the other hand, should be used as a last-ditch cleanup effort for de-registration. -Benjamin Johnston s355171@student.uq.edu.au
Technical Details
Message-ID:
<8s4972$43o$1@bunyip.cc.uq.edu.au>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<39e57bc3$1@server.local> <uDgF5.2142$wG1.4828@news-server.bigpond.net.au> <39e5962b$1@server.local>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10d6db,d25b87a070be9251 X-Google-Attributes: gid10d6db,public From: "Benjamin Johnston" <s355171@student.uq.edu.au> Subject: Re: How to cleanup when a class is destroyed ? Date: 2000/10/12 Message-ID: <8s4972$43o$1@bunyip.cc.uq.edu.au> X-Deja-AN: 680538475 References: <39e57bc3$1@server.local> <uDgF5.2142$wG1.4828@news-server.bigpond.net.au> <39e5962b$1@server.local> X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 X-Complaints-To: news@uq.edu.au X-Trace: bunyip.cc.uq.edu.au 971352098 4216 172.20.15.103 (12 Oct 2000 12:01:38 GMT) Organization: Benjamin Johnston X-MSMail-Priority: Normal NNTP-Posting-Date: 12 Oct 2000 12:01:38 GMT Newsgroups: aus.computers.java