Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happened internally (JVM) when System.gc() or finalize() method called?

What happened internally (JVM) when System.gc() or finalize() method called?

Is this really collect garbage or reduce performance ?

like image 938
Isabel Jinson Avatar asked May 21 '09 12:05

Isabel Jinson


1 Answers

Exactly what happens when you call System.gc() is JVM dependent. The JVM looks at this call as a suggestion that it might be a good time to run the garbage collector, so don't depend on it.

An object's finalize() method is run on an object by the garbage collector when the JVM determines that there are no more reachable references to that object. You shouldn't call it in your code. Keep in mind that finalize() is not called at the time when your program loses that final reference, but at a future time when the garbage collector is run, so don't depend on it happening at a specific point in time (or at all).

like image 117
Bill the Lizard Avatar answered Dec 16 '22 09:12

Bill the Lizard