Reputation:
I want to close a windows which is currently shown.
But when I call Close()
, it only hide the window.
And the memory length still grows instead of decreasing.
I also use this answer to fix this problem:
https://stackoverflow.com/a/34651426/9135351
but it doesn't work.
Here is my code to show a new Window and close the shown Window
C#
private void Home_Click(object sender, RoutedEventArgs e)
{
new HomeContentView().Show(); //Open Home window
Close(); //Close current window
GC.Collect(); //Realease
}
Xaml
<Button
ToolTip="Home"
Click="Home_Click"
Cursor="Hand"
Background="Transparent"
BorderBrush="Transparent"
Margin="0,0,221,0"
HorizontalAlignment="Right"
Width="48" Height="48"
VerticalAlignment="Top">
<materialDesign:PackIcon Kind="Home" Width="37" Height="38"
Foreground="Black" HorizontalAlignment="Stretch" />
</Button>
Upvotes: 0
Views: 1785
Reputation: 66
public void MyMethod()
{
var myWindow = this;
var control = myWindow.Content;
//do stuff
control = null; // is that okay??
myWindow.Close();
}
Upvotes: 0