J
Joe Warrington
is it possible to kill an instance of a class, and if so, how?
many thanks
Joe
many thanks
Joe
Joe Warrington said:is it possible to kill an instance of a class, and if so, how?
Tony said:No.
Read up on garbage collection.
John said:You can assist the garbage collector by assigning any references to the
class to null. It shouldn't make much difference, but does in practice.
Does it work if the class is a running thread?Virgil Green said:And then you could "suggest" to the garbage collector that it should run by
calling System.gc(). But, it's only a suggestion. There is no guarantee any
collection will be performed.
- Virgil
Liz said:Does it work if the class is a running thread?
class to null. It shouldn't make much difference, but does in practice.
One of the biggest myths on garbage collection is that removing all strong
references to an object (not a class) will make it eligible for garbage
collection.
Roedy said:What else is required?
Then the JVM must decide to clear all soft references to the object,
which it might delay if it isn't running tight on memory. It also has
to clear weak references, but those are usually cleared immediately
after the object is no longer softly reachable. (Phantom references
can't be used to retreive the object in question, so they don't need to
be cleared. They only need to be queued in their reference queue
sometime after the object they were pointing to was GC'd.)
Roedy said:I think people who set up their own weak/soft references/finalizers
are aware of this.
Carl Howells said:Perhaps with soft/weak references, they know. But I've seen far too
many people try to treat a finalizer as the same thing as a C++
destructor, not realizing what a mess that makes the GC process. I
wonder why Sun doesn't just mark finalize() as deprecated, and clearly
document how to use phantom references to do the same job with much
better performance.
Isn't finalize() supposed to be used to clean up resources that your
program did not get to clean up due to an exception? This is more than
references.
I was not paying close attention, you are correct.Roedy Green said:are you confusing finally with finalize?
Tony Morris said:One of the biggest myths on garbage collection is that removing all strong
references to an object (not a class) will make it eligible for garbage
collection.
This fallacy is the basis of your incorrect and somewhat over-generalised
statement.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.