Skip to content

Potential memory leak with dynamic maps #247

@adrianISI

Description

@adrianISI

I have been greatly enjoying this repo, but I have recently experienced something I think might be a memory leak.

My goal is to dynamically load data and display it in the map without reloading the window. Since i have a lot of data I first visualise it as a FastMarkerCluster, then later draw the shapes once zoom level is large enough. My issue is related to the marker cluster that seems to not be deleted from cache in the browser. Each time new data is loaded, the memory increases. Below is a small sample code of the issue. Each time the button is clicked the memory usage increases. This will go on until the browser runs out of memory (increase N to have this happen faster)

import streamlit as st 
import numpy as np
from streamlit_folium import st_folium
import folium
from folium.plugins import FastMarkerCluster

def load_marker_data(N=10000):
    return np.random.rand(N, 2) - 0.5

if "marker_data" not in st.session_state:
    st.session_state["marker_data"] = load_marker_data()
m = folium.Map(location=[0, 0], zoom_start=8)
fg = folium.FeatureGroup()
fg.add_child(FastMarkerCluster(st.session_state["marker_data"]))
st_folium(m, feature_group_to_add=fg, use_container_width=True)

st.button("Simulate new data loading", on_click=lambda: st.session_state.update({"marker_data": load_marker_data()}))

I have tried many different variations to make this work (like clearing cache, rerunning and so on), but have so far been unsuccessful. The overall behaviour of the code above is good, the map is never redrawn, however the memory usage increasing is a problem.

It would be great if someone could help me with getting the correct behaviour or look into if this is an actual bug.

PS. duplicate of #245 that i accidently closed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions