Article View: aus.computers.java
Article #430How to cleanup when a class is destroyed ?
From: DavidL
Date: Thu, 12 Oct 2000 00:00
Date: Thu, 12 Oct 2000 00:00
51 lines
1990 bytes
1990 bytes
Hi all,
I have come to java from C++, where when you want to cleanup when a class is
destroyed you would write a destructor.
I am having trouble getting the same functionailty from java.
From what I have read, I understood that this was the function of the
"finalize" method.
However, I don't seem to be able to get it to work.
Take this example:
---------------------------------------------
class app
{
static public void main (String args[])
{
class1 c = new class1();
}
}
---------------------------------------------
class class1
{
public class1 ()
{
System.out.println ("class1()"):
}
protected void finalize ()
{
System.out.println ("class1.finalize()");
}
}
---------------------------------------------
My expectation is that if I compile and run "app" I would see:
class1()
class1.finalize()
but instead I just see
class1()
This tells me that the finalize method is not being run.
Am I missing something here ?
Ta
DavidL
Technical Details
Message-ID:
<39e57bc3$1@server.local>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10d6db,d25b87a070be9251,start X-Google-Attributes: gid10d6db,public From: "DavidL" <email.address@in.message> Subject: How to cleanup when a class is destroyed ? Date: 2000/10/12 Message-ID: <39e57bc3$1@server.local> X-Deja-AN: 680490320 X-Original-NNTP-Posting-Host: 192.168.0.5 X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 X-Complaints-To: news@bigpond.net.au X-Authenticated-User: davidl X-Trace: news-server.bigpond.net.au 971341155 144.132.179.174 (Thu, 12 Oct 2000 19:59:15 EST) Organization: BigPond Internet Services (http://www.bigpond.net.au) X-Original-Trace: 12 Oct 2000 19:52:19 +1100, 192.168.0.5 X-MSMail-Priority: Normal NNTP-Posting-Date: Thu, 12 Oct 2000 19:59:15 EST Newsgroups: aus.computers.java