title: Static member of reference type inside non-static class and garbage collection
body: <p>Is static member of reference type inside non-static class may affect garbage collection when will not be set to null?</p>
  
  <hr>
  
  <p>Playing role of static member of reference type: 
  <strong><em>specialManagerSingletonRef</em></strong><br>
  Playing role of non-static class: <strong><em>SpecialProperty</em></strong> </p>
  
  <p>Let's assume following (let's go with an example!):</p>
  
  <ul>
  <li><p>We have 60 000 instances of <strong><em>SpecialProperty</em></strong> created and initialized (code of <strong><em>SpecialProperty</em></strong> below)</p></li>
  <li><p>Each <strong><em>SpecialProperty</em></strong> requires <strong><em>SpecialManagerSingleton</em></strong> <em>(and right now it is resolving it from DI container)</em></p></li>
  <li><p>We have three objects: <strong><em>ObjectA</em></strong>, <strong><em>ObjectB</em></strong>, <strong><em>ObjectC</em></strong> each have collection of 20 000 of SpecialProperties </p></li>
  <li><p>At some time point, all three: <strong><em>ObjectA</em></strong>, <strong><em>ObjectB</em></strong>, <strong><em>ObjectC</em></strong> are intended for destruction and are not needed any more in the application and then each calls Dispose() as they implement IDisposable interface. When Dispose() is called their collections wich held SpecialProperties are cleared out <em>(and so from now on noone is referencing any of this 60 000 SpecialProperties)</em></p></li>
  </ul>
  
  <p>Are these 60 000 SpecialProperties going to be garbage collected as soon as possible even if <strong>specialManagerSingletonRef</strong> won't be set to null ? </p>
  
  <p>I am not sure how this static member which is helding reference to <strong>SpecialManagerSingleton</strong> may affect garbage collection as from what logic tells me every object which has reference to other won't be garbage collected and without nulling the <strong>specialManagerSingletonRef</strong> we may have a memory leak then <em>(or atleast until the singleton's classloader is eligible for collection which in this case will be at the time of application closing!).</em> But maybe GC will treat this scenario differently?</p>
  
  <p>Refering to this <a href="https://stackoverflow.com/questions/3887532/a-question-about-static-members-inside-non-static-classes-and-garbage-collection">static-members-inside-non-static-classes-and-garbage-collection</a> - all 60 000 SpecialPropertys are going to be garbage collected.</p>
  
  <pre><code>    public class SpecialProperty : IDisposable
      {
  
       /** Is this member going to block gc from collecting, SpecialProperty 
           if we won't set it to null? **/
      private static SpecialManagerSingleton specialManagerSingletonRef; 
      private IUnityContainer container;
  
      public SpecialProperty(IUnityContainer container)
      {
          this.container = container;
      }
  
      public SpecialManagerSingleton SpecialManager
      {
          get
          {
              if (specialManagerSingletonRef == null)
              {
                  specialManagerSingletonRef = container.Resolve&lt;SpecialManagerSingleton&gt;();
              }
  
              return specialManagerSingletonRef;*emphasized text*
          }
      }
  
      public void Dispose()
      {
  
          //do i need to set specialManagerSingletonRef to null to get this SpecialProperty instance garbage collected??
  
      }
  }
  </code></pre>