Re: doubt abt finalizer method



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.
.



Relevant Pages

  • Re: doubt abt finalizer method
    ... > i heard grabase collector vll reclaim the space for nameless objects ... > stmt's execution it vll reclaim space.if this is correct the finalizer ... I gave up on decyphering your message after the first sentence. ... write correct sentences. ...
    (comp.lang.java.programmer)
  • doubt abt finalizer method
    ... i heard grabase collector vll reclaim the space for nameless objects ... immediately after execution.because no wa y after that stmt v can refer ... stmt's execution it vll reclaim space.if this is correct the finalizer ...
    (comp.lang.java.programmer)
  • Re: fortran and unit testing
    ... and then using this as the dummy argument of a subroutine with INTENT. ... the result is finalized before execution of the first executable statement in the scoping unit. ... I don't think there are any restrictions on what a finalizer subroutine ...
    (comp.lang.fortran)
  • Re: Destructors are useless?
    ... the execution of some finalizer. ... Michi. ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)