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 - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -