Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8265406

Testbug: fix fragile pattern in memory leak related tests

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P5
    • tbd
    • jfx16
    • javafx

    Description

      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();

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated: