import com.sun.javafx.perf.PerformanceTracker; import java.util.ArrayList; import java.util.List; import javafx.animation.AnimationTimer; import javafx.animation.KeyFrame; import javafx.animation.Timeline; import javafx.application.Application; import javafx.application.Platform; import javafx.collections.*; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.stage.Stage; import javafx.util.Callback; import javafx.util.Duration; public class TableColumnMemTest extends Application { static double SCENE_WIDTH = 800.0; static double SCENE_HEIGHT = 600.0; static int COLUMNS_PER_ITER = 10; Stage stage; TableView tableView; PerformanceTracker perfTracker; int iters; @Override public void start(Stage primaryStage) { stage = new Stage(); Group rootGroup = new Group(); Scene scene = new Scene(rootGroup, SCENE_WIDTH, SCENE_HEIGHT); tableView = new TableView(); tableView.setPrefSize(SCENE_WIDTH-10, SCENE_HEIGHT-10); rootGroup.getChildren().add(tableView); stage.setScene(scene); stage.sizeToScene(); stage.show(); perfTracker = PerformanceTracker.getSceneTracker(scene); Timeline fpsTimeline = new Timeline(); fpsTimeline.setCycleCount(Timeline.INDEFINITE); KeyFrame fpsKeyFrame = new KeyFrame(Duration.seconds(2), new EventHandler() { @Override public void handle(ActionEvent e) { String fpsText = String.format("FPS: %.2f", perfTracker.getInstantFPS()); System.out.println(fpsText); } }); fpsTimeline.getKeyFrames().add(fpsKeyFrame); AnimationTimer objectsAllocator = new AnimationTimer() { boolean stop = false; @Override public void handle(long l) { //if (iters %2 == 0) { // tableView.getColumns().clear(); //} else { TableColumn col; for (int i = 0; i < COLUMNS_PER_ITER; i++) { col = new TableColumn("" + i); col.setMaxWidth(20); tableView.getColumns().add(col); } //} iters ++; System.out.println("Created columns: " + (iters * COLUMNS_PER_ITER)); } }; fpsTimeline.play(); objectsAllocator.start(); } public static void main(String[] args) { for (int index = 0; index < args.length; index++) { String arg = args[index]; if ("-columns".equals(arg)) { if (index+1 >= args.length) { System.err.println("-columns numer of columns to create per iter"); System.exit(1); } try { COLUMNS_PER_ITER = Integer.parseInt(args[index+1]); } catch (IllegalArgumentException e) { System.err.print("-columns option must be Integer"); System.exit(1); } index++; } } System.out.println("Args: columns per iter: " + COLUMNS_PER_ITER); Application.launch(TableColumnMemTest.class, args); } }