-
Bug
-
Resolution: Fixed
-
P3
-
7u6
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.
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.