FXMisc / Flowless

Efficient VirtualFlow for JavaFX
BSD 2-Clause "Simplified" License
187 stars 39 forks source link

Possible memory leak on scrolling virtual flow #122

Open PavelTurk opened 1 month ago

PavelTurk commented 1 month ago

I use virtual flow - and I noticed that on scrolling used java memory added 200 MB. Firstly I thought that something was wrong with my code, but the same problem I found using RichTextFX.

This is test code:

public class JavaFxTest10 extends Application {

    @Override
    public void start(Stage stage) throws IOException {
        var path = Paths.get("/home/pavel/Temp/RichTextFX/richtextfx/src/main/java/org/fxmisc/richtext/GenericStyledArea.java");
        String content = Files.readString(path, StandardCharsets.UTF_8);
        var codeArea = new CodeArea(content);
        var scrollPane = new VirtualizedScrollPane(codeArea);
        VBox.setVgrow(scrollPane, Priority.ALWAYS);
        Scene scene = new Scene(new VBox(scrollPane), 500, 200);
        stage.setScene(scene);
        stage.show();
        codeArea.selectRange(30, 200);

    }

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

And this is the result (system monitor + test application):

Peek 2024-10-09 14-24

As I understand that with virtual flow same row instances are used for all text lines, then why used memory increased so significantly?

Jugen commented 1 month ago

Can you drill down and see what's taking up the memory ?

PavelTurk commented 6 days ago

@Jugen This is what I've found out:

Screenshot from 2024-11-12 01-03-39

These diagrams shows my two scrolling actions . It seems that extra memory is consumed for calculations when scrolling is done, but when scrolling finishes then memory is cleared.

Before scrolling: Screenshot from 2024-11-12 01-17-02

During scrolling: Screenshot from 2024-11-12 01-17-23