Articles in this section
Category / Section

How to dispose an instance of the SfTextBoxExt control by using the Dispose method?

1 min read

The memory of a control can be managed by using the GarbageCollector that releases the memory stored in the Heap. Sometimes the unmanaged resources like stream reader, stream writer, DataBase connectivity, etc. when used causes further leaks in the memory of a control. To free these unmanaged resources, you can use the Dispose method.

Dispose Method:

The dispose method is available in the IDisposable interface and it is used for the controls that implement the IDisposable interface and its signature is as follows:

C#

public interface IDisposable 
{void Dispose();
}
  1. The following is an example of using the Dispose method for the SfTextBoxExt control to release the unmanaged resources.

XAML

//To create the Button control in the MainWindow.
<Window x:Class="SfTextBoxMemoryLeak.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Syncfusion="clr-namespace:Syncfusion.Windows.Controls.Input;assembly=Syncfusion.SfInput.Wpf"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
      <Button Click="NewButton_Click" Content="Click to Dispose" Width="100" Height="55"></Button>      
    </Grid>
</Window>
  1. The following code example shows how to create a SfTextBoxExt in a new Window.

XAML

//To create a SfTextBoxExt in a new Window.
<Window x:Class="SfTextBoxMemoryLeak.SfTextBoxWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:Syncfusion="clr-namespace:Syncfusion.Windows.Controls.Input;assembly=Syncfusion.SfInput.Wpf"
        Title="SfTextBoxWindow" Height="300" Width="300">
    <Grid>
      <Syncfusion:SfTextBoxExt Name="SfTextBox" Width="150" Height="23" Text="SfTextBoxExt"/>
    </Grid>
</Window>
  1. The following code explains using the Dispose Method for the SfTextBoxExt control:

C#

private SfTextBoxWindow NewWindow;
       public MainWindow()
        {
            InitializeComponent();           
        }
        private void NewButton_Click(object sender, RoutedEventArgs e)
        {
            NewWindow = new SfTextBoxWindow();
            NewWindow.Show();
            NewWindow.Closing += NewWindow_Closing;      
        }
        private void NewWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            NewWindow.Closing -= NewWindow_Closing;
//Dispose method is used for the SfTextBoxExt to release the unmanaged resources.
            NewWindow.SfTextBox.Dispose();
            NewWindow = null;
        }

 

Conclusion

I hope you enjoyed learning about how to dispose an instance of the SfTextBoxExt control by using the Dispose method.

You can refer to our WPF TextBox feature tour page to know about its other groundbreaking feature representations. You can also explore our WPF TextBox documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied