JavaFX breakdown leaking on setPageFactory?

In the example below, if you continue to click the "Next Group" button, eventually the application heap will be exhausted. Set the heap on a small number such as -mx50m -ms50m and it will quickly hit the ceiling. You can see the memory consumption of the classic staircase having something like JVisualVM. When profiling with MyKit, many instances of objects from javafx packages were discovered. * And java. * Which are not CG'ed. setPageFactory seems to be the culprit. Perhaps this bit of code does something wrong, but so far I suspect that the JavaFX 2.2 Pagination kernel is running Windows 8, JDK 1.7_60. The same problem is observed with Window 8, Java FX 8, JDK 1.8_05.

Is this a problem with an example or JavaFX Pagination.setPageFactory?

public class PaginationSample extends Application {
    private static final String[] PAGE_TEXTS_0 = {"Time wounds all heals.", "The more I see, the less I know for sure.", 
    "Reality leaves a lot to the imagination.", "It weird not to be weird."};
    private static final String[] PAGE_TEXTS_1 = {"Fermions", "Quarks", "Leptons", "Bosons", "Gluon", "Graviton"};
    private static final String[] PAGE_TEXTS_2 = {"AAAAAAA", "BBBBB", "CCCCCCCC"};
    private static final String[][] ALL_GROUPS = {PAGE_TEXTS_0, PAGE_TEXTS_1, PAGE_TEXTS_2};

    private int groupIndex;

    @Override
    public void start(Stage stage) {
        final Pagination pagination = new Pagination();
        setPagesGroup(pagination);

        Button button = new Button("Next group");
        button.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent actionEvent) {
                nextGroup();
                setPagesGroup(pagination);
            }
        });

        BorderPane pane = new BorderPane();
        pane.setCenter(pagination);
        pane.setBottom(button);

        stage.setScene(new Scene(pane, 400, 250));
        stage.setTitle("What leaking?");

        stage.show();
    }

    private void setPagesGroup(Pagination pagination) {
        pagination.setPageFactory(createPageFactory());
        pagination.setPageCount(ALL_GROUPS[groupIndex].length);
    }

    private Callback<Integer, Node> createPageFactory() {
        return new Callback<Integer, Node>() {
            @Override
            public Node call(Integer pageIndex) {
                return createPage(ALL_GROUPS[groupIndex][pageIndex]);
            }

            private Node createPage(String text) {
                return new Label(text);
            }
        };
    }

    private void nextGroup() {
        if (++groupIndex == ALL_GROUPS.length) {
            groupIndex = 0;
        }
    }

    public static void main(String... args) {
        launch(args);
    }
}

. .

YourKit showing heap being consumption while clicking the button

:

//  pagination.setPageFactory(createPageFactory());

, , factory , setPageCount PaginationSkin resetIndexes. setPageFactory, setPageCount PaginationSkin.resetIndexes . , - PaginationSkin.java?

+4
1

, , .

https://javafx-jira.kenai.com/browse/RT-38058

Java 7 8

    pagination.setPageFactory(...);
    pagination.setPageCount(...);

.


PaginationSkin .

http://hg.openjdk.java.net/openjfx/2.2.2/master/rt/file/98d1e63be240/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/PaginationSkin.java

, IndicatorButton :

@ line 1179

            getSkinnable().getStyleClass().addListener(new ListChangeListener<String>() {
                @Override
                public void onChanged(Change<? extends String> change) {
                    setIndicatorType();
                }
            });


@ line 1197

            tooltipVisibleProperty().addListener(new ChangeListener<Boolean>() {
                @Override
                public void changed(ObservableValue<? extends Boolean> ov, Boolean oldValue, Boolean newValue) {
                    setTooltipVisible(newValue);
                }
            });

- , IndicatorButton node (getChildren.clear()). IDE, IndicatorButton static, . , . , .

:

  • PaginationSkin ( ) Pagination ( pagination.setSkin CSS).
  • IndicatorButton release(), .
  • , getChildren.clear() , , IndicatorButton.
+5

All Articles