diff --git a/examples/select_file_with_information_view.rs b/examples/select_file_with_information_view.rs index f83fbeff..206e553a 100644 --- a/examples/select_file_with_information_view.rs +++ b/examples/select_file_with_information_view.rs @@ -2,7 +2,7 @@ use std::path::PathBuf; use eframe::egui; use egui_file_dialog::information_panel::InformationPanel; -use egui_file_dialog::FileDialog; +use egui_file_dialog::{DialogState, FileDialog}; struct MyApp { file_dialog: FileDialog, @@ -54,6 +54,13 @@ impl eframe::App for MyApp { self.selected_file = Some(path.to_path_buf()); } + match self.file_dialog.state() { + DialogState::Closed | DialogState::Cancelled => { + self.information_panel.forget_all_stored_images(ui); + } + _ => {} + } + ui.label(format!("Selected file: {:?}", self.selected_file)); }); } diff --git a/src/information_panel.rs b/src/information_panel.rs index 0131d7a3..98abd7aa 100644 --- a/src/information_panel.rs +++ b/src/information_panel.rs @@ -350,8 +350,8 @@ impl InformationPanel { self.stored_images.shift_remove_index(0); } - #[allow(dead_code)] - fn forget_all_stored_images(&mut self, ui: &Ui) { + /// removes all loaded preview images from the egui-loaders to reduce memory usage. + pub fn forget_all_stored_images(&mut self, ui: &Ui) { for image in &self.stored_images { ui.ctx().forget_image(format!("file://{image}").as_str()); }