Petr Nejedl? discovered that surrounding variable definition with { } does not guarantee it to be removed from stack
1.1 --- a/samples/gc/test/org/apidesign/gc/CompilerSurprisesTest.java Fri Oct 24 21:15:50 2008 +0200
1.2 +++ b/samples/gc/test/org/apidesign/gc/CompilerSurprisesTest.java Wed Oct 29 17:41:37 2008 +0100
1.3 @@ -85,6 +85,14 @@
1.4 }
1.5 // END: compiler.surprises.fix.final
1.6
1.7 +// BEGIN: compiler.surprises.scope
1.8 + @Test public void canItBeHeldByNoLongerExistingScopeSurprisingly() {
1.9 + {
1.10 + Object val = factory();
1.11 + }
1.12 + assertNotGC("Surprisingly this variable cannot be GCed, even val is out of scope!!!!", cache);
1.13 + }
1.14 +// END: compiler.surprises.scope
1.15
1.16 private static void assertGC(String msg, Reference<?> ref) {
1.17 NbTestCase.assertGC(msg, ref);