I have a simple class :
public partial class MainWindow : Window
{
MyClass c1, c2, c3;
public MainWindow()
{
InitializeComponent();
}
private void Button1_Click(object sender, RoutedEventArgs e)
{
c1 = new MyClass();
c2 = new MyClass();
c3 = new MyClass();
}
private void Button2_Click(object sender, RoutedEventArgs e)
{
c1 = null;
c2 = null;
c3 = null;
GC.Collect();
}
}
class MyClass
{
String[] s;
public MyClass()
{
s= new String[1000000];
}
}
When I click button1, The managed memory (Bytes in all heaps counter, perfmon) is growing up (as expected). But when I click button2, I expect that managed memory should be released. But it also grow up !! And only after second button2 click, the memory released. What is an explanation for this behavior??
And why, when application just started, the "Bytes in all heaps counter" is 0? I think it should be more than 0 .There are some objects already allocated on managed heap. MainWindow for example.. Thank you, all