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

Multi-JFrame/JFXPanel app leaks JFXPanels

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 7u6
    • Fix Version/s: 7u6
    • Component/s: javafx
    • Labels:

      Description

      The following application dumps OutOfMemoryError after about 40 seconds:

      public class LeakTest extends Application {
          
          private JFrame frame;

          public static void main(String[] args) {
              launch(args);
          }
          
          @Override
          public void start(Stage primaryStage) {
              primaryStage.setScene(new Scene(new Group(), 500, 500));
              primaryStage.show();
              
              Timeline timeline = new Timeline();
              timeline.setCycleCount(Timeline.INDEFINITE);
              EventHandler<ActionEvent> handler = new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent e) {
                      SwingUtilities.invokeLater(new Runnable() {
                          @Override
                          public void run() {
                              recreateFrame();
                          }
                      });
                  }
              };
              timeline.getKeyFrames().add(
                      new KeyFrame(Duration.millis(1000), handler));
              timeline.play();
          }

          private void recreateFrame() {
              if (frame != null) {
                  frame.dispose();
              }

              final JFXPanel jfxPanel = new JFXPanel();
              
              frame = new JFrame();
              frame.setSize(500, 500);
              frame.getContentPane().setLayout(new BorderLayout());
              frame.getContentPane().add(BorderLayout.CENTER, jfxPanel);
              frame.setLocationRelativeTo(null);
              frame.setVisible(true);
              
              Platform.runLater(new Runnable() {
                  @Override
                  public void run() {
                      GridPane gridPane = new GridPane();
                      for (int i = 0; i < 10; i++) {
                          for (int j = 0; j < 10; j++) {
                              gridPane.add(new TextArea("test"), i, j);
                          }
                      }
                      Scene scene = new Scene(gridPane);
                      jfxPanel.setScene(scene);
                  }
              });
          }
      }

      Profiling suggests that TextAreas, JFXPanel, and Scenes created by the application are never garbage collected and are held by the java.awt.dnd.DragSource.dflt static field via SwingDnd and a chain of DnDEventMulticaster objects.

      The problem was originally reported against WebView running inside JFXPanel but appears to not be WebView-specific.

        Attachments

          Activity

            People

            • Assignee:
              asemenyuk Alexey Semenyuk
              Reporter:
              vbaranov Vasiliy Baranov (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported: