1

I'm trying to figure out if I should be worried about memory usage for this situation. I would like to launch lots of "lnk" shortcuts in a c# application. I'm wondering why I see a memory usage difference between launching lnk files vs launching exe files:

Process proc = new Process();

for (int i = 0; i < 20; i++) 
{
  proc.StartInfo.FileName = "c:\\somefolder\\shortcut.lnk"; //vs "c:\\somefolder\\someapp.exe"
  proc.Start();
}

The main c# program uses around 500 kilobytes per shortcut launched. Even after the "shortcut launched" applications close this memory never seems to be freed.

I've tried doing proc.close() or proc.dispose(), and I've forced the garbage collector to run to see what will happen. Nothing I do change the "shortcut launched" memory usage.

In contrast, when I launch the executables directly, the main program doesn't appear to use more memory per process launched.

zefram12
  • 11
  • 2

1 Answers1

0

In contrast, when I launch the executables directly, the main program doesn't appear to use more memory per process launched

Shortcut is nothing in itself. It is just a pointer to the main executable. So assuming/claiming that running from shortcut is taking more memory cannot be true.

The main c# program uses around 500 kilobytes per shortcut launched. Even after the "shortcut launched" applications close this memory never seems to be freed.

if you think that process is not freeing up memory, you can use it in using

using (Process proc = new Process())
{
     proc.StartInfo.FileName = "c:\\somefolder\\shortcut.lnk";
     proc.Start();
}
Ehsan
  • 31,833
  • 6
  • 56
  • 65
  • I've tried wrapping it a using like this, but it makes no difference. The shortcut launched applications are obviously treated differently. – zefram12 Aug 30 '13 at 12:32
  • To be clear: The launched application isn't using any more memory. The application launching the shortcut is using more memory. – zefram12 Aug 30 '13 at 12:34