I have a quite complex app - a video editor.
At startup, I have a wizard that will allow the user to:
- select the photos/videos
- music to include in the final video.
When the wizard finishes, I show the main editor, and the user can press "Play".
For the 2 first windows (a. select photos/videos + b. music to include), I have them as UserControl
classes. I place them in the top grid of the main window, and then I remove them, more or less:
private async Task show_async_full_screen(Func window_creator, Func check_func, Func result_func) where W : Control, IDisposable {
var w = window_creator();
main_grid.Children.Add(w);
await Task.Run(() => {
.... wait for control to end
});
var result = result_func(w);
main_grid.Children.Remove(w);
w.Dispose();
return result;
}
The problem is this:
the two controls or some parts of them (the "select photos"/"select music"), still remain in memory, eating resources and eating CPU
.
This is really bad, since it makes my app sluggish (every now and then, freezing for about 100ms or so).
I know the issue is the above 2 controls, since if i remove them (and preselect photos/music - for testing), the freezing does not occur.
How can I fully unload a control -- so that it releases all its resources and does not eat any CPU?