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

Memory leaks in the AWT on macOS

XMLWordPrintable

    • b03
    • generic
    • os_x

        While working on some other bug, i found a few memory leaks which may cause the application crash because of not enough of memory:

        Test to reproduce, you need to wait hour or so, depends from the system:

        import java.awt.Color;
        import java.awt.Frame;
        import java.awt.Point;
        import java.awt.Robot;
        import java.util.List;

        /**
         * @test
         * @key headful
         * @bug 8215105
         * @summary tests that Robot can capture the common colors without
         * artifacts
         */
        public final class CheckCommonColors {

            private static final Frame frame = new Frame();
            private static Robot robot;

            public static void main(final String[] args) throws Exception {
                robot = new Robot();
                try {
                    test();
                } finally {
                    frame.dispose();
                }
            }

            private static void test() {
                frame.setSize(400, 400);
                frame.setLocationRelativeTo(null);
                frame.setUndecorated(true);
                while (true)
                    for (final Color color : List.of(Color.WHITE, Color.LIGHT_GRAY,
                                                     Color.GRAY, Color.DARK_GRAY,
                                                     Color.BLACK, Color.RED, Color.PINK,
                                                     Color.ORANGE, Color.YELLOW,
                                                     Color.GREEN, Color.MAGENTA,
                                                     Color.CYAN, Color.BLUE)) {
                        frame.dispose();
                        frame.setBackground(color);
                        frame.setVisible(true);
                        checkPixels(color);
                    }
            }

            private static void checkPixels(final Color color) {
                int attempt = 0;
                Point p = frame.getLocationOnScreen();
                Color pixel = robot.getPixelColor(p.x + frame.getWidth() / 2,
                                                  p.y + frame.getHeight() / 2);
                if (color.equals(pixel)) {
                    return;
                }
            }
        }

              serb Sergey Bylokhov
              serb Sergey Bylokhov
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: