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 grid creation #61

Open
lcorrigan opened this issue Jan 15, 2024 · 1 comment
Open

Memory leak in grid creation #61

lcorrigan opened this issue Jan 15, 2024 · 1 comment

Comments

@lcorrigan
Copy link

I've only started using ipyaggrid but I'm exited about using it in standalone HTML reports.

However, I've found that creating grid objects seem to have a memory leak. Every time I create a grid into the same variable name, the memory usage increases. Even if I delete the variable and do a garbage collection, it continues to climb. My use-case is a follows:

  1. Run a query from a database into a pandas dataframe
  2. Pass the dataframe to a function in a .py file (griddler, shown below) that returns a grid from the string representation of the dataframe with a list of columns to pin. I.e.: Not much too it.

I'm using:
ipyaggrid 0.5.1
ipykernel 6.25.2
ipython 8.14.0
ipywidgets 8.0.3

I'm having to cache my database query results to tinker around with ipyaggrid because I have to restart the kernel so often to get the RAM back down.

I'm open to workarounds if anyone can help with that.

def griddler(df, pin_list=[], height=400):
    
    col_defs = ipyaggrid.Util.build_colDefs_for_si_cols(df)

    for d in col_defs:
        if "field" in d.keys():
            if d['field'] in pin_list:
                d['pinned'] = 'left'
            
    grid_options = {
        'columnDefs' : col_defs,
        'enableSorting': True,
        'enableFilter': True,
        'enableColResize': True,
        'enableRangeSelection': True,
    }

    df_str = pd.DataFrame()

    for c in df.columns:
        df_str[c] = df[c].astype("string")

    g = None
        
    g = ipyaggrid.Grid(grid_data=df_str,         
            height=400,
            grid_options=grid_options,
            quick_filter=True,
            sync_on_edit=False,
            show_toggle_edit=True,
            export_csv=True,
            theme='ag-theme-blue',
            show_toggle_delete=False,
            columns_fit='auto',
            index=False,
            keep_multiindex=False,
            sync_grid=False)

    return g
@lcorrigan
Copy link
Author

Just to help paint the picture on this:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant