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);
}
}
. .

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