When is finalize() method gets executed?
Does it run automatically? Or do I need to call the finalize() method from
one of the codes. i.e inside windowClosing(WindowEvent e) method?
--
Best Regards,
Wing Hoe
---------------------------------------------------------------
ICQ: 2213281
Email: winghoe@hotmail.com
www: http://pwp.maxis.net.my/winghoe
---------------------------------------------------------------
Re: When is finalize() method gets executed?
The finalize() method of an object runs automatically when (and if) the
object is garbage-collected. You should not call it yourself.
PC2
Lim Wing Hoe <winghoe@hotmail.com> wrote in message
news:39f55787@news.devx.com...
> Does it run automatically? Or do I need to call the finalize() method from
> one of the codes. i.e inside windowClosing(WindowEvent e) method?
>
Re: When is finalize() method gets executed?
Absolutely not you can't acheive garbage collection by making this=null;
The garbage collection only happens when the object in the heap doesn't have
any references in the stack.
"Lim Wing Hoe" <winghoe@hotmail.com> wrote:
>OK, let's say, if I want ObjectA itself to be garbage collected, can I set
>it as,
>
>this = null;
>System.gc();
>
>and then tell Java to collect it? And then in the finalize() method, I
>perform whatever cleaning up tasks, yes?
>
>--
>
>
>
>Best Regards,
>Wing Hoe
>---------------------------------------------------------------
>ICQ: 2213281
>Email: winghoe@hotmail.com
>www: http://pwp.maxis.net.my/winghoe
>---------------------------------------------------------------
>
>
>"Paul Clapham" <pclapham@core-mark.com> wrote in message
>news:39f59ad9@news.devx.com...
>> The finalize() method of an object runs automatically when (and if) the
>> object is garbage-collected. You should not call it yourself.
>
>
>
Re: When is finalize() method gets executed?
OK, let's say, if I want ObjectA itself to be garbage collected, can I set
it as,
this = null;
System.gc();
and then tell Java to collect it? And then in the finalize() method, I
perform whatever cleaning up tasks, yes?
--
Best Regards,
Wing Hoe
---------------------------------------------------------------
ICQ: 2213281
Email: winghoe@hotmail.com
www: http://pwp.maxis.net.my/winghoe
---------------------------------------------------------------
"Paul Clapham" <pclapham@core-mark.com> wrote in message
news:39f59ad9@news.devx.com...
> The finalize() method of an object runs automatically when (and if) the
> object is garbage-collected. You should not call it yourself.
Re: When is finalize() method gets executed?
No. Garbage collection is not your responsibility. Your responsibility is
to not keep references to objects unnecessarily. You will probably never
need to call System.gc() unless you have some kind of unusual performance
problem.
As for the finalize() method, do not put any code in there that MUST be
called. There is no guarantee that it will ever be called. If you have
cleaning up tasks that MUST be done, put them in some other method and call
that method when you want to clean up.
PC2
Lim Wing Hoe <winghoe@hotmail.com> wrote in message
news:39f5c04c@news.devx.com...
> OK, let's say, if I want ObjectA itself to be garbage collected, can I set
> it as,
>
> this = null;
> System.gc();
>
> and then tell Java to collect it? And then in the finalize() method, I
> perform whatever cleaning up tasks, yes?
>