Posted 22 July 2024, 11:08 am EST
Hi Kartik,
Thanks for the reply. The issue is that without the Loaded/Unloaded events, there is a memory leak. But with the Loaded/Unloaded events, there is a stack overflow.
I’ve combined the sample projects into a new one that demonstrates the issue. As written, it demonstrates the memory leak when the windows containing the FlexGrid are closed. You can uncomment lines 46-47 of Tab1.xaml.cs to fix the memory leak, but doing so will trigger a Stack Overflow Exception when switching between tabs.
// Tab1.xaml.cs:
private void C1FlexGrid_Unloaded(object sender, RoutedEventArgs e)
{
// Uncomment to fix memory leak
// However, switching tabs causes StackOverflow Exception.
// C1FlexGridFilterService.SetFlexGridFilter(c1FlexGrid, null);
// C1FlexGridFilterService.SetFullTextFilterBehavior(c1FlexGrid, null);
}
I am using the Loaded/Unloaded events because the FlexGrid is in a UserControl, not hosted in the Window directly. Hence, I do not have access to the OnClosing method you suggested as a workaround.
However, I recently realized I might be able to use the Window.GetWindow() method from within the UserControl to register an event handler on Window.Closed. This would let me apply the workaround even from a nested UserControl. I will let you know if this approach is successful on the real application.
FlexGridFilterLeak2.zip