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
Post a Comment