< prev index next >
test/javax/swing/UIDefaults/6795356/bug6795356.java
Print this page
rev 1576 : 6464022: Memory leak in JOptionPane.createDialog
Reviewed-by: alexp
*** 24,33 ****
--- 24,35 ----
/*
* @test
* @bug 6795356
* @summary Leak caused by javax.swing.UIDefaults.ProxyLazyValue.acc
* @author Alexander Potochkin
+ * @library ../../regtesthelpers
+ * @build Util
* @run main bug6795356
*/
import java.lang.ref.WeakReference;
import java.security.ProtectionDomain;
*** 56,100 ****
}, new AccessControlContext(new ProtectionDomain[]{domain}));
weakRef = new WeakReference<ProtectionDomain>(domain);
domain = null;
! // Generate OutOfMemory and check the weak ref
! generateOOME();
if (weakRef.get() != null) {
throw new RuntimeException("Memory leak found!");
}
System.out.println("Test passed");
}
-
- static void generateOOME() {
- List<Object> bigLeak = new LinkedList<Object>();
- boolean oome = false;
- System.out.print("Filling the heap");
- try {
- for(int i = 0; true ; i++) {
- // Now, use up all RAM
- bigLeak.add(new byte[1024 * 1024]);
- System.out.print(".");
-
- // Give the GC a change at that weakref
- if (i % 10 == 0) {
- System.gc();
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- } catch (OutOfMemoryError e) {
- bigLeak = null;
- oome = true;
- }
- System.out.println("");
- if (!oome) {
- throw new RuntimeException("Problem with test case - never got OOME");
- }
- System.out.println("Got OOME");
- }
}
--- 58,70 ----
}, new AccessControlContext(new ProtectionDomain[]{domain}));
weakRef = new WeakReference<ProtectionDomain>(domain);
domain = null;
! Util.generateOOME();
if (weakRef.get() != null) {
throw new RuntimeException("Memory leak found!");
}
System.out.println("Test passed");
}
}
< prev index next >