I am trying to reduce memory usage of a winForm application.
There is a main form and a setting form in the application. When "Setting" button been pressed, the setting form will popup as a modal form, the Setting form will load app.config data from config file and read them to memory as Hashtable. After the setting form closed, it will call Dispose method inherented from Windows.Forms.Form. The Dispose method is as simple as set the Hashtables and app.config object to null.
Show SettingForm as modalform:
private void btnSettings_Click(object sender, EventArgs e)
{
frmConfig form = new frmConfig();
form.StartPosition = FormStartPosition.CenterScreen;
//MessageBox.Show(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase));
form.ShowDialog(this);
form.Dispose();
}
Dispose method:
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
// Release managed resources
Logger.Verbose("Disposing SettingForm");
mySetting = null;
testFtp = null;
}
base.Dispose(disposing);
}
Note: mySetting is a instance of Class with all the app.config data been load into Hashtable, and testFtp is a custom object for ftp function. Should I implement Dispose method for this two class and using
mySetting.Dispose();
testFtp.Dispose();
instead of set them to null, as they are themself/deal with unmanaged resources?
But each time push the "Setting" button and close the setting form will increase private Byte for a few hundreds K. Memory leak? How could I get rid of it?