我知道C#是一种自动垃圾收集语言,但如果我处理一个表单,我会注意到它有什么区别吗?例如:
SettingsDialog dialog;
private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
{
dialog = new SettingsDialog();
dialog.ShowDialog();
dialog.FormClosed += new FormClosedEventHandler(dialog_FormClosed);
}
void dialog_FormClosed(object sender, FormClosedEventArgs e)
{
dialog.Dispose();
}
或者我应该把它留作:
private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
{
SettingsDialog dialog = new SettingsDialog();
dialog.ShowDialog();
}
此外,如果SettingsDialog消耗大量内存,该怎么办?这会有所作为吗?
提前致谢