title: C# class instance with static method vs static class memory usage
body: <p>How does C#, or other languages for that matter, handle memory allocation (and memory de-allocation) between these two scenarios:</p>
  
  <p>1.)  A method on a static class is invoked.</p>
  
  <pre><code>public Program {
      Foo foo = Loader.load();
  }
  
  public static Loader {
      public static Foo load() {
          return new Foo();
      }
  }
  </code></pre>
  
  <p>2.)  A method is invoked on an instance, which then falls out of scope.</p>
  
  <pre><code>public Program {
      Foo foo = new Loader().load();
  }
  
  public Loader {
      public Foo load() {
          return new Foo();
      }
  }
  </code></pre>
  
  <p>I suppose the static class is loaded, and remains, in memory; whereas the class instance succumbs to garbage collection at C#'s leisure.  Are there any pros or cons to these two paradigms?  Is there ever a time when you have a class that never needs to be instantiated (i.e. some sort of resource loader or factory), but you use the second methodology anyway to take advantage of garbage collection?</p>
  
  <p>The important part of my question is whether or not the first paradigm, while being conceptually correct in some circumstances, may suffer from holding on to memory unnecessarily.</p>