first of all sorry for my english.
I found a memory leak in my code, and I don't know what else I need to do to solve it.
I'm doing the follow in all my code. I created a UserControl to simulate a window called DragItem. this only have a XML with header and Border to attach his content. The content is another UserControl as a parameter. So, when I call a new "window" I do it as follow:
var detectionInfo = new DetectionInfoPage(_projectPage.searchControl, SelectedBookmark._Object, _projectId, SelectedBookmark);
var window = new DragItem(_mainTask, _mainTask.ContentMainTask)
{
Name = "dragDetectionInfo",
Title = "Detection Info",
UserControl = detectionInfo,
ModalWidth = 800,
ModalHeight = 500
};
detectionInfo.Initialize();
window.Show();
detectionInfo.onDetectionSaved += (o, bookmark) =>
{
SearchBookmarks();
};
window.OnClose += (o, b) =>
{
detectionInfo?.Destroy();
detectionInfo = null;
_mainTask.ContentMainTask.Children.Remove(window);
GC.Collect();
};
I'm trying to destroy all elements and callbacks and all inside of the content "UserControl" in OnClose callback and I remove from tree the DragItem instance ("window"), and furthermore call the garbage collector... It disapears from the visible contents and I can interact with the interface normally, but the code behind the UserControl content is still working.. and sometimes I have a backgroud tasks for example "uploading files" and this process still working, is not killed.
What else I missing? How I can KILL the UserControls inside other usercontrols in WPF??
Thanks in advance!!!!