Hi Sandeep
I am not clear on the second point. Could you please elaborate?
Rajnish
On Jun 29, 9:30 pm, Sandeep Kadyan <
sandeep.kad...@gmail.com> wrote:
> Hey folks,
>
> I have following opinion about the usage of finalize() method. I would say
> that we should never relay on *finalize()* method and *do not *use it.
> The *finalize()* method was invented to resemble the destructor of C++ or to
> provide a chance to free up resources that cannot be freed automatically by
> an automatic storage manager.
>
> Before the storage for an object is reclaimed by the garbage collector, the
> Java virtual machine will invoke the finalizer* *of that object. But it is
> not specified anywhere how sooner the finalize method will be invoked.except
> to say that it will happen before the storage for the object is reused. So
> there can be following point which impose various reasons to don't use the *
> finalize*() method.
>
> 1. Time not gurantted:We never know how sooner the finalize method will
> invoked after GC is about to going to relaim the memory.
> 2. It is possible that the this object( on which *finalize*() method is
> invoked) can put the reference for this object some where which means the
> object's memory should be reclaim by GC.
> 3. It is also not specified that which thread or threads (on
> multi-processor) will invoked the *finalize()*. If during clean-up, the
> thread block somewhere or required any use specified lock. it going to be *BIG
> PROBLEM* as we will never get to know what exaclty happen and why the memory
> is not reclaim even thought everything is fine (except the *finalize()*)
> 4. The Java imposes no ordering on finalize method calls. the
> *finalize()*method may be called in any order, or even concurrently as
> specified in
> previous point.
>
> Thanks,
> Sandeep Kadyan
> e-M@il:
sandeep.kad...@gmail.com
> Skype IM: sandeep.kadyan
> YIM:
thekadi...@yahoo.com
> Cell:-
+91 99116 14500
>
>
>
> On Mon, Jun 29, 2009 at 8:52 PM, Rajnish <
rajnis...@gmail.com> wrote:
>
> > Hi All
>
> > I am bit confused on how should I use finalize method to make the best
> > use out of it? After all if this method is in JAVA API there must be
> > some LOGIC to have this method.
>
> > Please comment on use of finalize?- Hide quoted text -
>
> - Show quoted text -