+ 1
What is the function of finalize in java?
as per my knowledge Finalize () in java is used for end up codes before the object is removed from heap . System.gc i.e garbage collector is responsible for deallocation of memory . If m wrong please correct me up
4 Respuestas
+ 2
What they mean is Garbage collection is performed by a daemon thread called Garbage Collector(GC). This thread calls the finalize() method before object is garbage collected.
+ 1
finalize() acts similar to a destructor for a java class. finalize() does NOT call the garbage collector. In fact it is the other way around. The garbage collector calls the finalize() method of a class just before the object is about to be garbage collected. This can happen any time after the object becomes eligible for GC. An object becomes eligible only when there are no more references to that object. If you were to explicitly call the finalize() method of an object it will still be called again by the GC when eligible and just before collection. The finalize() method is where you should do any necessary clean up, such as freeing up any held resources, closing a connection, etc.
0
Yes, Absolutely correct!
0
but in Java challenge here in solo learn they are keeping ans as finalize is used to deallocation memory