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?
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.
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
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.
Oh, well, that kinda brief me in more, thanks henry :)
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.