-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Altair charts causes memory leak on browser side #1148
Description
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)