Cómo aumentar la memoria fija cada vez que los datos de actualización Tableview

Mahmud Fathy:

Tenía un torreón de memoria de aplicaciones JavaFX aumentando en el tiempo más. Esto me confunde, porque pensé que tenía una pérdida de memoria en mi código. He encontrado aumento de memoria cada vez que los datos de actualización Tableview, no hay ningún objeto nuevos acaba de actualizar los datos antiguos.

La intención del código siguiente es reproducir el mismo problema

public class TableViewSample extends Application {

    private boolean running = false;

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

    @Override
    public void start(Stage stage) {
        Scene scene = new Scene(new Group());
        stage.setTitle("Table View Sample");

        TableView<Foo> table = new TableView<>();
        ObservableList<Foo> data = FXCollections.observableArrayList(
                new Foo(0, 0, 0, 0), new Foo(0, 0, 0, 0), new Foo(0, 0, 0, 0),
                new Foo(0, 0, 0, 0), new Foo(0, 0, 0, 0), new Foo(0, 0, 0, 0),
                new Foo(0, 0, 0, 0), new Foo(0, 0, 0, 0), new Foo(0, 0, 0, 0),
                new Foo(0, 0, 0, 0), new Foo(0, 0, 0, 0), new Foo(0, 0, 0, 0),
                new Foo(0, 0, 0, 0), new Foo(0, 0, 0, 0), new Foo(0, 0, 0, 0),
                new Foo(0, 0, 0, 0), new Foo(0, 0, 0, 0), new Foo(0, 0, 0, 0),
                new Foo(0, 0, 0, 0), new Foo(0, 0, 0, 0), new Foo(0, 0, 0, 0),
                new Foo(0, 0, 0, 0), new Foo(0, 0, 0, 0), new Foo(0, 0, 0, 0),
                new Foo(0, 0, 0, 0), new Foo(0, 0, 0, 0), new Foo(0, 0, 0, 0)
        );
        Random random = new Random();

        TableColumn<Foo, Integer> num1Col = new TableColumn<>("num1");
        num1Col.setCellValueFactory(new PropertyValueFactory<>("num1"));
        TableColumn<Foo, Integer> num2Col = new TableColumn<>("num2");
        num2Col.setCellValueFactory(new PropertyValueFactory<>("num2"));
        TableColumn<Foo, Integer> num3Col = new TableColumn<>("num3");
        num3Col.setCellValueFactory(new PropertyValueFactory<>("num3"));
        TableColumn<Foo, Integer> num4Col = new TableColumn<>("num4");
        num4Col.setCellValueFactory(new PropertyValueFactory<>("num4"));

        table.setItems(data);
        table.getColumns().addAll(num1Col, num2Col, num3Col, num4Col);

        Timeline timeline = new Timeline(new KeyFrame(Duration.seconds(1), event -> {
            for (Foo foo : data) {
                foo.setNum1(random.nextInt(1000));
                foo.setNum2(random.nextInt(1000));
                foo.setNum3(random.nextInt(1000));
                foo.setNum4(random.nextInt(1000));
            }
        }));
        timeline.setCycleCount(Timeline.INDEFINITE);

        Button btn = new Button("start");
        btn.setOnAction(event -> {
            if (running) {
                timeline.stop();
                running = false;
                btn.setText("start");
            } else {
                timeline.play();
                running = true;
                btn.setText("stop");
            }
            event.consume();
        });

        VBox vbox = new VBox();
        vbox.getChildren().addAll(btn, table);
        ((Group) scene.getRoot()).getChildren().add(vbox);

        stage.setScene(scene);
        stage.show();

    }

    public static class Foo {
        private SimpleIntegerProperty num1;
        private SimpleIntegerProperty num2;
        private SimpleIntegerProperty num3;
        private SimpleIntegerProperty num4;


        public Foo(int num1, int num2, int num3, int num4) {
            this.num1 = new SimpleIntegerProperty(num1);
            this.num2 = new SimpleIntegerProperty(num2);
            this.num3 = new SimpleIntegerProperty(num3);
            this.num4 = new SimpleIntegerProperty(num4);
        }

        public int getNum1() {
            return num1.get();
        }

        public SimpleIntegerProperty num1Property() {
            return num1;
        }

        public void setNum1(int num1) {
            this.num1.set(num1);
        }

        public int getNum2() {
            return num2.get();
        }

        public SimpleIntegerProperty num2Property() {
            return num2;
        }

        public void setNum2(int num2) {
            this.num2.set(num2);
        }

        public int getNum3() {
            return num3.get();
        }

        public SimpleIntegerProperty num3Property() {
            return num3;
        }

        public void setNum3(int num3) {
            this.num3.set(num3);
        }

        public int getNum4() {
            return num4.get();
        }

        public SimpleIntegerProperty num4Property() {
            return num4;
        }

        public void setNum4(int num4) {
            this.num4.set(num4);
        }
    }
}

Estoy haciendo algo mal y cómo solucionar este aumento de la memoria?

Mahmud Fathy:

probado mismo código en ventanas con la misma versión de JDK y todo está bien. Yo he construido jar ejecutable en ubuntu dos veces utilizando diferentes versiones de JDK y lo ha probado en Windows y Ubuntu y dar lugar a la misma cuestión en ambas plataformas. por lo ubuntu JDK producen el mismo problema, no importa lo JDK versión se utiliza, voy a seguir en las ventanas de codificación para el presente y a tratar una instalación de ubuntu fresca tarde. gracias por ayudar

edit: después de algún búsqueda encontró algunos informes de errores relacionados JDK-8161997 , JDK-8.161.911 parece que el problema relacionado con JavaFX está utilizando tubería de hardware. después de una nueva instalación de Ubuntu 18.04 todo funciona bien.

Supongo que te gusta

Origin http://43.154.161.224:23101/article/api/json?id=192210&siteId=1
Recomendado
Clasificación