JDK-8215756 : Memory leaks in the AWT on macOS
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 11,12,13
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: os_x
  • CPU: generic
  • Submitted: 2018-12-20
  • Updated: 2020-02-20
  • Resolved: 2019-01-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 13 Other
11.0.5Fixed 13 b03Fixed openjdk8u252Fixed
Description
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;
        }
    }
}


Comments
I have updated my patch for jdk8u so that the original patch copyright date is preserved. discussion: https://mail.openjdk.java.net/pipermail/jdk8u-dev/2020-February/011180.html updated webrev: http://cr.openjdk.java.net/~stooke/webrevs/jdk-8215756-jdk8u/03/jdk.03/
19-02-2020

Waiting on resolution of copyright header changes
18-02-2020

Fix Request I would like to backport this to jdk8u, to increase reliability of AWT programs. webrev: http://cr.openjdk.java.net/~stooke/webrevs/jdk-8215756-jdk8u/02/jdk.02/ discussion: https://mail.openjdk.java.net/pipermail/jdk8u-dev/2019-July/009914.html https://mail.openjdk.java.net/pipermail/jdk8u-dev/2019-August/009943.html
26-08-2019

I've confirmed this patch applies cleanly on 11u, I'd like to request it be backported to increase AWT reliability in long-running GUI applications, please.
30-07-2019