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

Prune old egui memory data when reaching some limit #3299

Merged
merged 8 commits into from
Sep 4, 2023
Merged

Conversation

emilk
Copy link
Owner

@emilk emilk commented Sep 4, 2023

Previously egui would just accumulate state over time, growing its memory more and more if the user had unique Ids with persisted state, e.g. a lot of CollapsingHeaders or Windows with different names. This leads to slow load and save of eframe apps with persistence.

With this PR egui will now forget the oldest data of each type that hasn't been read in a while. That is, if you load and save your app state many times, egui will eventually drop the thing that never been read.

The limit can be set with egui_ctx.memory_mut(|m| m.data.set_max_bytes_per_type(1_000_000));

The default is 256 kiB per type. For reference, a CollapsingHeader takes around 200 bytes to store, so that's over a thousand different collapsing headers in your application.

@emilk emilk added the egui label Sep 4, 2023
@emilk emilk merged commit 8c84bbf into master Sep 4, 2023
@emilk emilk deleted the emilk/memory-gc branch September 4, 2023 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a way to clear storage
1 participant