public class Inner { static Object keep; void run() { keep = new Object() {}; } protected void finalize() throws Throwable { System.out.println("finalize"); } public static void main(String[] args) throws Exception { new Inner().run(); System.gc(); Thread.sleep(1000L); System.out.println("done"); } }