fork download
  1.  
  2. public partial class Form1 : Form
  3. {
  4. public Form1()
  5. {
  6. InitializeComponent();
  7. }
  8.  
  9. private void button1_Click(object sender, EventArgs e)
  10. {
  11. var f = new UserControl1() { AllowDrop = false};
  12. this.Controls.Add(f);
  13. this.Controls.Remove(f);
  14. GCCheck();
  15. }
  16.  
  17. private void button2_Click(object sender, EventArgs e)
  18. {
  19. var f = new UserControl1() { AllowDrop = true};
  20. this.Controls.Add(f);
  21. this.Controls.Remove(f);
  22. GCCheck();
  23. }
  24. private void GCCheck()
  25. {
  26. var a = GC.GetTotalMemory(false);
  27. var b = GC.GetTotalMemory(true);
  28. Console.WriteLine("GC Before=" + a + " After=" + b);
  29. }
  30. }
  31.  
  32.  
  33. public partial class UserControl1 : UserControl
  34. {
  35. public UserControl1()
  36. {
  37. InitializeComponent();
  38. }
  39. ~UserControl1()
  40. {
  41. Console.WriteLine(this.GetType().Name + "は解放されました " + "{AllowDrop = " + this.AllowDrop + " }");
  42. }
  43. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty