Here is my situation. I am building a small Windows Form that will launch on Startup and run minimized in the System tray while not in use. The user will open the Form via a Notify Icon in the System tray and after submitting the form, the app will minimize back down to the System tray.
This all works fine. However, I noticed something a little odd. When the program is first launched, the Mem Usage in Task Manager shows ~14000 K. If I then open the Form from the system tray, it kicks up to ~16000 K. If I then minimize the form back down to the system tray, the usage drops to < 1000 K which is good. I have tried launching the application and waiting to see if the Usage dropped over time, but saw no change.
The reason I am concerned about this is because the application will be running in a Citrix Environment, so I would like to keep the Memory usage per instance down when the application is not in use, but I would prefer to not have to have the user open the application and minimize it every morning when they login.
If anyone has any suggestions or tips, I would greatly appreciate it. I will include the main blocks of code below.
public Form1()
{
InitializeComponent();
WindowState = FormWindowState.Minimized;
notifyIcon1.DoubleClick += new EventHandler(notifyIcon1_DoubleClick);
Rectangle r = Screen.PrimaryScreen.WorkingArea;
this.StartPosition = FormStartPosition.Manual;
this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - this.Width, Screen.PrimaryScreen.WorkingArea.Height - this.Height);
currentWorkstation = Environment.GetEnvironmentVariable("clientname");
if (currentWorkstation == null)
currentWorkstation = Environment.MachineName;
GC.KeepAlive(notifyIcon1);
GC.KeepAlive(currentWorkstation);
}
private void Form1_Resize(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
Hide();
}
Thank you for your help.
The fake “drop” in memory is because during a minimize event, Windows transfers the majority of application memory to virtual memory. During your startup, you’re probably never actually closing a form/minimizing the application, therefore the cleanup never occurs.
More information can be seen here:
https://micksmix.wordpress.com/2010/01/08/why-does-task-manager-show-an-applications-memory-usage-drop-after-minimizing-it-to-the-the-taskbar/
My knowledge of this only comes from using this as a way to trick the J++ GC into running. Telling a windows application to minimize/restore is nearly imperceptible to the user, but minimizes RAM accrual in a managed-memory VM. I highly doubt this is “best practices” but it makes the numbers-guys in management happy.