Testbug: fix fragile pattern in memory leak related tests

XMLWordPrintable

    • Type: Bug
    • Resolution: Unresolved
    • Priority: P5
    • tbd
    • Affects Version/s: jfx16
    • Component/s: javafx

      the brittle pattern analysed in review (by Kevin, https://github.com/openjdk/jfx/pull/409/commits/da0820a9d08ac1a3acbd8b594432bc425a206433#r614171861) :

          WeakReference<SomeClass> ref = new WeakReference<>(new SomeClass());
           ref.get().doStuff();
           attemptGC();

      citing Kevin: "This is fragile. It is possible, although unlikely, that the referent could be GCed between its construction in the previous statement (after which it goes out of scope), and this statement. If this rare event happened, it would cause an NPE here. I recommend to keep a local reference to the referent and then set it to null after this (and before the attemptGC)."

      The pattern is used elsewhere, f.i. BehaviorCleanupTest, ListViewTest, TabPaneTest, SkinCleanupTest, SkinLabeledCleanupTest, SkinMemoryLeakTest and should be fixed as suggested, that is

            SomeClass some = new SomeClass();
            WeakReference<SomeClass> ref = new WeakReference<>(some);
            some.doStuff(); // could also be moved up a line now
            some = null;
             attemptGC();

            Assignee:
            Jeanette Winzenburg
            Reporter:
            Jeanette Winzenburg
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: