java - finalize() not getting called -


why finalize() not being called here. code compiled , ran there wasn't output.

package temp;  public class temp {      int i;      temp(int j) {         = j;     }      public void finalize() {         if (i == 10) {             system.out.println("finalize called.");         }     }      public static void main(string[] args) {         temp obj = new temp(10);         system.gc();     }  } 

your call system.gc(); makes no difference, since temp instance has reference (obj) it's not eligible garbage collection.

even if eligible garbage collection, calling system.gc(); doesn't collect objects have no reference them immediately.


Comments

Popular posts from this blog

java - Unable to make sub reports with Jasper -

Save and close a word document by giving a name in R -

scala - play framework: Modules were resolved with conflicting cross-version suffixes -