using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace OcppDummyClient
{
public partial class Form1 : Form
{
public string[] messages = new string[]
{
"Authorize",
"BootNoficiation"
};
public Panel A;
public Panel B;
public Form1()
{
InitializeComponent();
InitializeForm();
A = new Panel()
{
Width = this.flowLayoutPanel1.Width,
Height = this.flowLayoutPanel1.Height,
BackColor = Color.Black
};
A.Controls.Add(new Button()
{
Text = "Button"
});
B = new Panel()
{
Width = this.flowLayoutPanel1.Width,
Height = this.flowLayoutPanel1.Height,
BackColor = Color.Blue
};
B.Controls.Add(new Button()
{
Text = "Button2"
});
this.flowLayoutPanel1.Controls.Add(A);
this.flowLayoutPanel1.Controls.Add(B);
}
public void InitializeForm()
{
this.comboBox1.Items.AddRange(messages);
}
private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
{
string SelectedValue = this.comboBox1.Text.ToString();
switch(SelectedValue)
{
case "Authorize":
{
A.Visible = true;
B.Visible = false;
break;
}
case "BootNoficiation":
{
A.Visible = false;
B.Visible = true;
break;
}
default:
{
break;
}
}
}
}
}
That is my whole code and I want to know why memory leak is occurred when I changed combobox with event handler(comboBox1_SelectedValueChanged). I thought memory leak not happened because I already created panel and just changed panel property(visible).