We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Platform: WPF |
Control: SfTextBoxExt |
Published Date: February 13, 2015 |
Last Revised Date: June 24, 2019 |
.NET Framework: 4.5.1 |
Product Version: 12.4.0.24

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;
        }

 

2X faster development

The ultimate WPF UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon