< prev index next >

test/java/awt/TrayIcon/PopupMenuLeakTest/PopupMenuLeakTest.java

Print this page

        

*** 42,51 **** --- 42,52 ---- public class PopupMenuLeakTest { static final AtomicReference<WeakReference<TrayIcon>> iconWeakReference = new AtomicReference<>(); static final AtomicReference<WeakReference<PopupMenu>> popupWeakReference = new AtomicReference<>(); static ExtendedRobot robot; + static Frame popupMenuParentFrame; public static void main(String[] args) throws Exception { robot = new ExtendedRobot(); SwingUtilities.invokeAndWait(PopupMenuLeakTest::createSystemTrayIcon); sleep();
*** 70,90 **** TrayIcon icon = iconWeakReference.get().get(); if (icon == null) { throw new RuntimeException("Failed: TrayIcon collected too early"); } SystemTray.getSystemTray().remove(icon); } private static void assertCollected(WeakReference<?> reference, String message) { java.util.List<byte[]> bytes = new ArrayList<>(); for (int i = 0; i < 5; i ++) { try { while (true) { bytes.add(new byte[1024]); } } catch (OutOfMemoryError err) { - bytes = new ArrayList<>(); } } if (reference.get() != null) { throw new RuntimeException(message); } --- 71,94 ---- TrayIcon icon = iconWeakReference.get().get(); if (icon == null) { throw new RuntimeException("Failed: TrayIcon collected too early"); } SystemTray.getSystemTray().remove(icon); + + PopupMenu menu = popupWeakReference.get().get(); + popupMenuParentFrame.remove(menu); + popupMenuParentFrame.dispose(); } private static void assertCollected(WeakReference<?> reference, String message) { java.util.List<byte[]> bytes = new ArrayList<>(); for (int i = 0; i < 5; i ++) { try { while (true) { bytes.add(new byte[1024]); } } catch (OutOfMemoryError err) { } } if (reference.get() != null) { throw new RuntimeException(message); }
*** 135,147 **** --- 139,157 ---- return trayImage; } private static PopupMenu createTrayIconPopupMenu() { + popupMenuParentFrame = new Frame(); + popupMenuParentFrame.setSize(200, 200); + popupMenuParentFrame.setVisible(true); + final PopupMenu trayIconPopupMenu = new PopupMenu(); final MenuItem popupMenuItem = new MenuItem("TEST!"); trayIconPopupMenu.add(popupMenuItem); + + popupMenuParentFrame.add(trayIconPopupMenu); return trayIconPopupMenu; } private static void sleep() { robot.waitForIdle(100);
< prev index next >