Re: how to destroy object from inside?
From: Andy Fish (ajfish_at_blueyonder.co.uk)
Date: 05/06/04
- Next message: Michael Borgwardt: "Re: Don't do this at home"
- Previous message: Kevin Burges: "JDK 1.4.1, Xalan, and extensions"
- In reply to: vertigo: "Re: how to destroy object from inside?"
- Next in thread: Steve Horsley: "Re: how to destroy object from inside?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 06 May 2004 12:09:07 GMT
I'm guessing maybe your problem is that you want to explicitly close or
terminate other resources owned by your class without waiting for the
garbage collector to free the memory.
e.g. say your class has a file or a socket open, or a datbase connection or
owns a window or something like that.
in this case, include a terminate method in your class which explicitly
closes those resources. obviously you need to make sure you don't ever
access the object after you have called the terminate
don't rely on the finalize() method to do these things unless you really
don't care when they get closed. Given that file handles and database
connections are limited resources, you should always care about when they
get closed unless you're just about to exit the JVM.
In my experience of java programming I have never yet written a finalize
method.
Andy
"vertigo" <none@microsoft.com> wrote in message
news:c7cq28$n77$1@atlantis.news.tpi.pl...
>
>
>
> > You must get rid of all references pointing to your MyClass object. That
> > will tell the JVM it *can* free the memory allocated for that object.
> > When it *does* free the memory might be right then, or at any moment
> > after that.
>
> but i do not have any references to that object.
> Instead it has references to other objects (other classes).
> It's because this class is in fact some sockets which
> receives data and prints in other window (other class).
>
> How can i destroy it ?
>
> Thanx
> Michal
>
- Next message: Michael Borgwardt: "Re: Don't do this at home"
- Previous message: Kevin Burges: "JDK 1.4.1, Xalan, and extensions"
- In reply to: vertigo: "Re: how to destroy object from inside?"
- Next in thread: Steve Horsley: "Re: how to destroy object from inside?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|