DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: When is finalize() method gets executed?

  1. #1
    Lim Wing Hoe Guest

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





  2. #2
    Paul Clapham Guest

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





  3. #3
    Ruchi Dhar Guest

    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.

    >
    >
    >



  4. #4
    Lim Wing Hoe Guest

    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.





  5. #5
    Paul Clapham Guest

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





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center