Results 1 to 6 of 6
  1. #1
    cruxblack is offline Senior Member
    Join Date
    Jul 2007
    Posts
    130
    Rep Power
    0

    Default Finalizers method?

    What do we use finalizers method for actually?
    Ive been reading some literature, and some said that it was to do some house-cleaning process before the garbage collector took over the cleaning work

    What i dun understand is, what house cleaning process?:confused:
    Anyone can help me with an example of when and why we use a finalizers method?

    Thanks :)
    CruxBlack

  2. #2
    henry_78 is offline Member
    Join Date
    Aug 2007
    Posts
    47
    Rep Power
    0

    Default

    Hi,
    This method is the one that the garbage collector execute when he desides to eliminate an object from the memory.
    Naturally he cant eliminiate an object if it has a reference.

  3. #3
    cruxblack is offline Senior Member
    Join Date
    Jul 2007
    Posts
    130
    Rep Power
    0

    Default

    Mmm, correct me if im wrong, but isnt the objects got dump and the memory freed when we do System.exit(0)?
    When does the finalizers got called?
    And btw, is there any problem tat might require that we override the finalizers methods?
    I have seen some examples bout this overridings, but unfortunately, i didn't analyze them further or save the codes, so im still bit confused

  4. #4
    henry_78 is offline Member
    Join Date
    Aug 2007
    Posts
    47
    Rep Power
    0

    Default

    When u do Systm.exit(0) u terminate the whole virtual machine.
    the system.exit(n) --> calls another method in the class System.exit(n) method.
    The Runtime.exit(n) method when it is closing the vitual machine , one of its operations is to call all the uninvocaed finalize() methods.
    The finalize method free the memory of an object (make it available to be reused).
    From my point of view i think u will need to overwrite this method very rarely...only in some precise situations..Bye.

  5. #5
    cruxblack is offline Senior Member
    Join Date
    Jul 2007
    Posts
    130
    Rep Power
    0

    Default

    Oh, well, that kinda brief me in more, thanks henry :)

  6. #6
    palindrome is offline Member
    Join Date
    Aug 2007
    Posts
    6
    Rep Power
    0

    Default

    The garbage collector removes an object from memory when they are no more references to it - i.e. nothing is using it any more. If this didn't happen, you'd just keep using more and more memory as your program ran.

Similar Threads

  1. Replies: 2
    Last Post: 03-26-2010, 06:12 PM
  2. Method Help
    By pringle in forum New To Java
    Replies: 4
    Last Post: 04-16-2008, 02:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •