Limitations in WPF Spreadsheet (SfSpreadsheet)

23 Jul 20261 minute to read

Release memory held by AutomationPeer

SfSpreadsheet retains an instance in memory even after the spreadsheet is disposed or its sheets are removed. This happens because the WPF AutomationPeer holds memory that must be released manually. Use the following steps to release it.

Create a class derived from WindowAutomationPeer and override it’s GetChildrenCore method and returns “null” value that clears the AutomationPeer item from memory as follows

public class FakeWindowsPeer : WindowAutomationPeer
{

    public FakeWindowsPeer (Window window): base(window)
    { }

    protected override List<AutomationPeer> GetChildrenCore()
    {
        return null;
    }
}

Now override the OnCreateAutomationPeer of the window and it returns the class as follows.

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    protected override AutomationPeer OnCreateAutomationPeer()
    {
        return new FakeWindowsPeer(this);
    }
}

NOTE

For more information, see the WPF Spreadsheet Editor feature tour and the WPF Spreadsheet demos.