dash-ag-grid icon indicating copy to clipboard operation
dash-ag-grid copied to clipboard

memory leak: Column API Function getColumnState() cannot be called as the grid has been destroyed

Open dragonite00 opened this issue 2 years ago • 6 comments
trafficstars

I have a checklist that updates the page with a different set of ag-grid depending on the selected option. I get the following error image

dragonite00 avatar Aug 07 '23 19:08 dragonite00

Hello @dragonite00,

Could you please provide a working example of how you encounter this issue?

BSd3v avatar Aug 07 '23 19:08 BSd3v

hey, thanks for the response!

The setup is basically, I have a (pseudocode) dbc.RadioItems(id="checklist", options={1:1, 2:2, 3:3})

@callback(
     Output(display_id, "children"),
     Input("checklist", "value")
)
def update_all_tables(value):
    if value == 1:
        return [ag.Grid(), ag.Grid(), ag.Grid()]
    elif value == 2:
        # different set
        return [ag.Grid(), ag.Grid(), ag.Grid()],
    ....

if I click between the checklist values too quickly (actually it takes ~2s to return the ag grids so I'm not even clicking that fast), then I get the aforementioned error. along with a An object was provided as `children` instead of a component, string, or number (or list of those).

dragonite00 avatar Aug 07 '23 19:08 dragonite00

Hmm, interesting, have you tried using Patch with pre-existing grids?

In this style, I think you are encountering the issue because you are removing the grid before it can be fully spun up. We can take a look as see if there is something we can do to remove the events if the grid is removed before completely available.

Most api and columnApi functions will only occur after the grid is completely up, unless you are then trying to pass it data or columnDefs immediately...

You could also potentially use the new getApiAsync and getColumnApiAsync if you are trying to manipulate it.

BSd3v avatar Aug 07 '23 20:08 BSd3v

Hmm, interesting, have you tried using Patch with pre-existing grids?

hmm, if you mean have a fixed set of grids, it's not possible because the checklist also controls the number of grids

We can take a look as see if there is something we can do to remove the events if the grid is removed before completely available.

this would be amazing, since this pattern seems most "intuitive" to me

Most api and columnApi functions will only occur after the grid is completely up, unless you are then trying to pass it data or columnDefs immediately...

Hm, I thought passing columnDefs in the return ag.Grid is the standard practice (at least from https://dash.plotly.com/dash-ag-grid/getting-started). Do you mean I could avoid this issue if I return the ag grid object first, and then add a callback to pass coldefs later? edit: I just tried not passing coldefs on initialization, I still run into the exact same error

dragonite00 avatar Aug 07 '23 20:08 dragonite00

Can you please provide a working example of this?

I cannot dig into what is happening unless there is something to test with.

Are you also passing all the data and stuff to the grids too?

BSd3v avatar Aug 07 '23 20:08 BSd3v

Hello @dragonite00,

Could you give this a test on the v31 of the grid to see if this issue persists?

BSd3v avatar Apr 09 '24 17:04 BSd3v