1

If I have something like :

   public static class StaticClass
    {
        public static int x;

        public static void Do(int y)
        {
            x = y;
        }

    }

You can't instantiate StaticClass , so when will the garbage collector take care of it ?

Will it remain in memory for the entire lifetime of the performing executing application ?

JAN
  • 21,236
  • 66
  • 181
  • 318
  • It will remain in memory until the application closes. – SimpleVar Nov 26 '15 at 03:49
  • If your application is Asp.net then the static variable will be re-instantiated at the time of app pool recycle. Else, it will remain in memory until application restart/ close. – Ankit Vijay Nov 26 '15 at 03:55

1 Answers1

1

Will it remain in memory for the entire lifetime of the performing executing application ?

Yes. Since there's effectively always a "reference" to the static object, it will never get garbage collected.

D Stanley
  • 149,601
  • 11
  • 178
  • 240