Skip to content

Altair charts causes memory leak on browser side #1148

@remifaitout

Description

@remifaitout

Summary

I'm experiencing a memory leak browser side when using Altair charts. I can see memory used for the current tab growing each time I regenerate the chart. It is partly freed after 30-60s but not completely. It can lead to memory exhaustion and tab crash.

Steps to reproduce

I reproduce the issue with the simplified example code below :

import streamlit as st
import pandas as pd
import numpy as np
import altair as alt

@st.cache
def generate_data():
    df = pd.DataFrame(
        np.random.randn(40000, 3),
        columns=['a', 'b', 'c'])
    return df

data = generate_data()

a = st.radio("Swap", ['A/B', 'B/A'], 1)
if a == 'A/B':
    x = 'b'
    y = 'a'
else:
    x = 'a'
    y = 'b'

c = alt.Chart(data, width=500, height=500).mark_circle().encode(x=x, y=y, size='c', color='c')
st.altair_chart(c)

Browser tab memory grows each time you switch the radio button that regenerates the charts. It's visible in Windows task explorer, as well as in Chrome debug tools (Memory tab > Total JS Heap size)

Expected behavior:

Memory usage for the page should be roughly constant

Actual behavior:

There's a spike in memory usage each time you regenerate the chart with the radio button (variable, from 30 to 100Mb), then it is partly freed under 1 minute. Once stable again, you can notice that memory usage is significantly higher than before (at least 10Mb, sometimes more).

Is this a regression?

Don't know

Debug info

  • Streamlit version: 0.56
  • Python version: 3.7.4
  • Using Conda? PipEnv? PyEnv? Pex? just pip
  • Altair version: 3.2.0
  • OS version: Windows 10.0.17134.165 (x64)
  • Browser version: Chrome 79.0.3945.130 (x64)

Additional information

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature:st.altair_chartRelated to the `st.altair_chart` elementtype:bugSomething isn't working as expected

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions