Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak in DataTable init method if the table should have a fixed size #664

Closed
HAC-jh opened this issue Jun 9, 2022 · 0 comments
Closed
Assignees
Labels
bug Something isn't working
Milestone

Comments

@HAC-jh
Copy link
Contributor

HAC-jh commented Jun 9, 2022

Describe the bug
There is a memory leak which occurs if the table config isFixed and because of that inside the DataTable init method the resize event listener is added to the DOM window object.

Proof of concept:

The DataTable is created and will be added again by pressing the load icon, which keeps the "old" DataTable in a detached state because of the listener and the garbage collector isn't able to remove it.

The usecase for adding a new DataTable to the card is to add columns after the data itself is refreshed, this is not part of the PoC

To Reproduce

public class Poc implements EntryPoint {

    private LocalListDataStore<DataObject> localListDataStore;

    private DataTable<DataObject> table;

    private final TableConfig<DataObject> tableConfig = new TableConfig<>();

    private final Card card = Card.create();

    @Override
    public void onModuleLoad() {

        Layout layout = Layout.create("PoC").show(ColorScheme.BLUE);

        tableConfig.setFixed(true);
        tableConfig.addColumn(ColumnConfig.<DataObject>create("Index", "Index")
                .setCellRenderer(cell -> TextNode.of(cell.getTableRow().getRecord().column1)));

        localListDataStore = new LocalListDataStore<>();
        table = new DataTable<>(tableConfig, localListDataStore);

        List<DataObject> data = new ArrayList<>();

        for (int i = 0; i <= 5; i++) {
            data.add(new DataObject(i, "Test"));
        }

        card.addHeaderAction(new HeaderAction(Icons.MDI_ICONS.refresh_mdi()).addClickListener((Event evt) -> {
            card.getBody().clearElement();

            localListDataStore = new LocalListDataStore<>();
            table = new DataTable<>(tableConfig, localListDataStore);

            card.appendChild(table);
            localListDataStore.setData(data);
        }));

        card.appendChild(table);

        layout.getContentPanel().appendChild(card);

    }

    private static class DataObject {

        Integer index;

        String column1;

        public DataObject(Integer index, String column1) {
            this.index = index;
            this.column1 = column1;
        }

    }

}

Expected behavior
No memory leak ;-)

Screenshots
grafik

State after several "loads"

Desktop (please complete the following information):
All

Smartphone (please complete the following information):
All

Additional context

@vegegoku vegegoku self-assigned this Jun 9, 2022
@vegegoku vegegoku added the bug Something isn't working label Jun 9, 2022
@vegegoku vegegoku added this to the 1.0.0-RC14 milestone Jun 9, 2022
vegegoku added a commit that referenced this issue Jun 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants