Details
-
Bug
-
Resolution: Fixed
-
P4
-
7u6
Description
The following program fails with OOME after about 10 minutes:
public class StrikeDescLeakTest extends Application {
private static final int ROW_COUNT = 30;
private static final int COLUMN_COUNT = 20;
private static final int NODE_WIDTH = 50;
private static final int NODE_HEIGHT = 22;
private static final int SCENE_WIDTH = NODE_WIDTH * COLUMN_COUNT;
private static final int SCENE_HEIGHT = NODE_HEIGHT * ROW_COUNT;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
Group group = new Group();
final ArrayList<Label> labels = new ArrayList<Label>();
for (int j = 0; j < ROW_COUNT; j++) {
for (int i = 0; i < COLUMN_COUNT; i++) {
Label label = new Label("(" + j + "," + i + ")");
label.setPrefSize(NODE_WIDTH, NODE_HEIGHT);
label.setTranslateX(i * NODE_WIDTH);
label.setTranslateY(j * NODE_HEIGHT);
group.getChildren().add(label);
labels.add(label);
}
}
Timeline timeline = new Timeline();
timeline.setCycleCount(Timeline.INDEFINITE);
EventHandler<ActionEvent> handler = new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
for (Label label : labels) {
double size = Math.random() * 50 + 10;
label.setFont(Font.font("Arial", size));
}
}
};
timeline.getKeyFrames().add(
new KeyFrame(Duration.millis(100), handler));
timeline.play();
Scene scene = new Scene(group, SCENE_WIDTH, SCENE_HEIGHT);
scene.setFill(Color.GRAY);
primaryStage.setScene(scene);
primaryStage.show();
}
}
Every 100 milliseconds the program generates 600 unique fonts and applies them to 600 labels. The program does not explicitly retain generated fonts anywhere and so is expected to be able to run forever.
Profiling shows that the program causes T2KCompositeFontResource.strikeMap to grow infinitely. Interestingly, the values stored in T2KCompositeFontResource.strikeMap are WeakReferences to FontStrikes, so FontStrikes go away nicely as the program progresses. The problem is, map entries are still referenced strongly, thus causing the map to grow infinitely as more and more unique fonts get generated by the program.
public class StrikeDescLeakTest extends Application {
private static final int ROW_COUNT = 30;
private static final int COLUMN_COUNT = 20;
private static final int NODE_WIDTH = 50;
private static final int NODE_HEIGHT = 22;
private static final int SCENE_WIDTH = NODE_WIDTH * COLUMN_COUNT;
private static final int SCENE_HEIGHT = NODE_HEIGHT * ROW_COUNT;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
Group group = new Group();
final ArrayList<Label> labels = new ArrayList<Label>();
for (int j = 0; j < ROW_COUNT; j++) {
for (int i = 0; i < COLUMN_COUNT; i++) {
Label label = new Label("(" + j + "," + i + ")");
label.setPrefSize(NODE_WIDTH, NODE_HEIGHT);
label.setTranslateX(i * NODE_WIDTH);
label.setTranslateY(j * NODE_HEIGHT);
group.getChildren().add(label);
labels.add(label);
}
}
Timeline timeline = new Timeline();
timeline.setCycleCount(Timeline.INDEFINITE);
EventHandler<ActionEvent> handler = new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
for (Label label : labels) {
double size = Math.random() * 50 + 10;
label.setFont(Font.font("Arial", size));
}
}
};
timeline.getKeyFrames().add(
new KeyFrame(Duration.millis(100), handler));
timeline.play();
Scene scene = new Scene(group, SCENE_WIDTH, SCENE_HEIGHT);
scene.setFill(Color.GRAY);
primaryStage.setScene(scene);
primaryStage.show();
}
}
Every 100 milliseconds the program generates 600 unique fonts and applies them to 600 labels. The program does not explicitly retain generated fonts anywhere and so is expected to be able to run forever.
Profiling shows that the program causes T2KCompositeFontResource.strikeMap to grow infinitely. Interestingly, the values stored in T2KCompositeFontResource.strikeMap are WeakReferences to FontStrikes, so FontStrikes go away nicely as the program progresses. The problem is, map entries are still referenced strongly, thus causing the map to grow infinitely as more and more unique fonts get generated by the program.
Attachments
Issue Links
- blocks
-
JDK-8118039 Out of memory in mimimized state
- Resolved
- relates to
-
JDK-8128295 Crash in WebPaneJava.dll
- Closed