Clarification about System.Drawing.Font and Dispose
#8.823 aberto em 10 de mai. de 2020
Métricas do repositório
- Stars
- (4.100 stars)
- Métricas de merge de PR
- (Mesclagem média 14d 22h) (56 fundiu PRs em 30d)
Description
- Docs says nothing unusual here:
Call Dispose when you are finished using the Font. The Dispose method leaves the Font in an unusable state. After calling Dispose, you must release all references to the Font so the garbage collector can reclaim the memory that the Font was occupying.
-
Designer assigning fonts this way:
someControl.Font = new System.Drawing.Font(...);and never Dispose them. -
In .net Font.Dispose(bool disposing) has an
[SuppressMessage("Microsoft.Usage", "CA2213:DisposableFieldsShouldBeDisposed")]attribute. But in core it's gone. -
There are many questions about Font and Dispose on stackoverflow (with variants answers): Should I dispose of the old font when changing the font of a control? How and when is Font disposed for WinForms controls Calling dispose() for Font in Windows form Windows Form Fonts Questions Part 1 and more...
If nothing special here (docs are correct), why Designer never call Font.Dispose then? Otherwise, can we have official clarification (update docs)?
Ups, sorry about api-suggestion label - my bad :( Pls remove it.