Hi,

I think it's really hard to say that all weak references would be reclaimed by just calling "System.gc()" 10 times.

Sergey's suggestion is much better. And I made another patch to fix this issue.
----------------------------------------------------------------------
diff -r 2345e253e677 test/jdk/java/beans/PropertyEditor/Test6397609.java
--- a/test/jdk/java/beans/PropertyEditor/Test6397609.java Thu Jan 03 15:54:01 2019 -0500 +++ b/test/jdk/java/beans/PropertyEditor/Test6397609.java Fri Jan 04 14:32:55 2019 +0800
@@ -32,6 +32,8 @@
  */

 import java.beans.PropertyEditorManager;
+import java.lang.ref.Reference;
+import java.util.Vector;

 public class Test6397609 {
     public static void main(String[] args) throws Exception {
@@ -44,6 +46,7 @@
         if (!isEditorExist(Object.class)) {
             throw new Error("the editor is lost");
         }
+        Reference.reachabilityFence(loader);
         loader = null; // clean the reference
         if (isEditorExist(Object.class)) {
             throw new Error("unexpected editor is found");
@@ -51,12 +54,22 @@
     }

     private static boolean isEditorExist(Class type) {
-        for (int i = 0; i < 10; i++) {
-            System.gc(); // clean all weak references
-            if (null == PropertyEditorManager.findEditor(type)) {
-                return false;
+        Vector<byte[]> garbage = new Vector<byte[]>();
+        // clean all weak references
+        while (true) {
+            try {
+                garbage.add(new byte[180306]);
+            }
+            catch (OutOfMemoryError e) {
+                break;
             }
         }
-        return true;
+        garbage = null;
+
+        if (null == PropertyEditorManager.findEditor(type)) {
+            return false;
+        } else {
+            return true;
+        }
     }
 }
----------------------------------------------------------------------
Would you please review it and give me some advice?
Thanks.

Best Regards,
Jie

On 2019/1/4 上午6:35, Sergey Bylokhov wrote:
I am not sure that "System.gc()" will cause to cleanup all
weak references, probably we should generate+catch the real OOM
at the second part of the test?


Reply via email to