I recently created a new WPF application having a loop in MainWindow.xaml that creates a new object of another page (Test.xaml) and creates a dialog of Test.xaml page. In Test.xaml i added a Textblock and updated the Text property on Loaded event and closing the page immediately.
Now when i ran the code, i saw that the memory used by this application is increasing continuously. Why is this really happening?
I am already disposing previous object and rewriting with new object, still it is increasing memory because of previous object.
What could be the reason behind it? How can i remove this behavior?
I tried creating the memory dump of the application to analyze memory leaks, there i saw that Hashtable, DependencyProperty and EventHandler are using the most of the memory.
MainWindow.xaml
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
int counter = 0;
Test test = null;
do
{
test = null;
test = new Test();
test.ShowDialog();
} while (++counter != 5000);
test = null;
}
Test.xaml
private void Test_Loaded(object sender, RoutedEventArgs e)
{
MyTextBox.Text = "Testing leaks";
Close();
}
My expectation is the object should be disposed of totally and should not contribute in memory increase.