title: Winforms GDI leak despite using static font or disposal of font?
body: <p>I have a static Font object in a Winforms Application. It's dynamically creating and destroying controls like edit boxes etc. On some the Font property is assigned from a static (singleton) Font object. Despite the fact that there is only one font object, every time(!) a control is destroyed and recreated using the same(!) font object, the GDI Object count increases by one. GDIView shows that this is a font object. When not assigning the Font property to the new control there is no GDI Object increase.</p>
  
  <p>I also tried to dynamically recreate the Font object every time a control is created and disposing it when the control is disposed, but it does not make a difference. </p>
  
  <p>Is this a bug in Winforms (.NET 4.5.2, VS2015, also tried .NET 3.5 ) or do I miss something? There are many questions here regarding GDI resource leaks but none answered my question.</p>
  
  <p>Here a small Winforms TestApp with only a single button on it initially to demonstrate the problem:</p>
  
  <pre><code>    private const string Todelete = "todelete";
  
  #if !DYNAMIC_FONT
      static readonly Font Font = new Font("Arial", 11, GraphicsUnit.Pixel);  
  #endif
      private void Button_Click(object sender, EventArgs e)
      {
          Controls.Find(Todelete, false).FirstOrDefault()?.Dispose();
  
          var ctrl = new TextBox();
  #if !DYNAMIC_FONT
          ctrl.Font = Font;//leaks GDI handle every time!
  #else
          ctrl.Font = new Font("Arial", 11, GraphicsUnit.Pixel); 
          // does not help:
          ctrl.Disposed += (sender2, args) =&gt; ((Control)sender2).Font.Dispose();
  #endif
          ctrl.Name = Todelete;
          Controls.Add(ctrl);
      }
  </code></pre>
  
  <p>btw. there are no USER Object leaks, so the control is deleted properly, but both variants leak a GDI Object every time the button is pressed. Not assigning the Font property resolves it, but how do I assign a Font without leak?</p>