diff --git a/modules/javafx.base/src/test/java/test/util/memory/JMemoryBuddy.java b/modules/javafx.base/src/test/java/test/util/memory/JMemoryBuddy.java index 19816bfe769..543f404677d 100644 --- a/modules/javafx.base/src/test/java/test/util/memory/JMemoryBuddy.java +++ b/modules/javafx.base/src/test/java/test/util/memory/JMemoryBuddy.java @@ -131,7 +131,7 @@ private static int checkCollectable(int stepsLeft, WeakReference weakReference) } /** - * Checks whether the content of the WeakReference can not be collected. + * Checks whether the content of the WeakReference cannot be collected. * @param weakReference The WeakReference to check. */ public static void assertNotCollectable(WeakReference weakReference) { @@ -141,11 +141,14 @@ public static void assertNotCollectable(WeakReference weakReference) { } /** - * Checks whether the content of the WeakReference can not be collected. + * Checks whether the content of the WeakReference cannot be collected. * @param weakReference The WeakReference to check. - * @return Returns true, when the provided WeakReference can not be collected. + * @return Returns true, when the provided WeakReference cannot be collected. */ public static boolean checkNotCollectable(WeakReference weakReference) { + createGarbage(); + System.gc(); + System.runFinalization(); createGarbage(); System.gc(); return weakReference.get() != null; @@ -212,11 +215,8 @@ public void setAsReferenced(Object ref) { throw new AssertionError("The following references should be collected: " + toBeCollectedMarked + " and " + toBeNotCollected.size() + " should not be collected: " + toBeNotCollectedMarked); } } - - } - static void createHeapDump() { if (createHeapdump) { try {