Re: doubt abt finalizer method
- From: Roedy Green <my_email_is_posted_on_my_website@xxxxxxxxxxxxxx>
- Date: Fri, 30 Dec 2005 18:34:59 GMT
On 30 Dec 2005 08:31:01 -0800, "chandu" <chandu.penjarla@xxxxxxxxx>
wrote, quoted or indirectly quoted someone who said :
>hi
>i heard grabase collector vll reclaim the space for nameless objects
>immediately after execution.because no wa y after that stmt v can refer
>it
>like it vll reclaim spce after System.out.println((new A()).i));this
>stmt's execution it vll reclaim space.if this is correct the finalizer
>class of class A has to be executed but it is not executing(some print
>stm i hav written in fainalize() method);
>next
> cont i xpect out put of finalize() method
>tell me plese as earli possible
I will first attempt a translation. I have never seen English like
that. I would be curious to learn how it came about.
I heard the garbage collector will reclaim the space for nameless
objects e.g. new Thing() in an expression not assigned to a variable)
immediately after execution because there is no way a variable can
refer to it.
For example, it will reclaim space after
System.out.println ( (new A()).i));
This statement's execution will reclaim space. If this is correct the
finalizer for class A has to be executed, but when I try it, I
discover the finalizer is not being called. Please explain this as
soon as possible.
First of all there is no guarantee the finalizer will be called. Java
won't call it unless it is desperate for space. In a simple test you
will exit without any finalizers called.
// Force finalize methods to be run on exit
// Without this, unreachable objects may not
// have had finalize run when you quit.
System.runFinalizersOnExit( true );
Next the finalizer has to have a particular pattern:
protected void finalize() throws Throwable {...}
Next finalize is an almost deprecated feature of Java. It is better to
keep track yourself of which elements need some sort of close called,
the way you do with files.
For more details see http://mindprod.com/jgloss/finalize.html
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
.
- References:
- doubt abt finalizer method
- From: chandu
- doubt abt finalizer method
- Prev by Date: Re: javac: how to get the FULL errors/warnings list?
- Next by Date: Re: The beauty of TCP/IP
- Previous by thread: Re: doubt abt finalizer method
- Next by thread: Taking the Contents of a File object and converting it to a byte array
- Index(es):
Relevant Pages
|