TextBoxたとえば、System.Drawing.FontFamily.GenericMonospaceおよびを使用してのフォントを設定しようとしていSystem.Drawing.SystemFonts.IconTitleFont.SizeInPointsます。
次のようなコードを使用する場合:
_TBTextBox.Font = new Font(System.Drawing.FontFamily.GenericMonospace, System.Drawing.SystemFonts.IconTitleFont.SizeInPoints);
.Net Memory ProfilerSystem.Drawing.Fontは、 のインスタンスと のインスタンスのSystem.Drawing.FontFamily両方が破棄されずにガベージ コレクションされていることを通知します。
フォント セットをusingブロックにラップすると、破棄の問題が解消されますが、効率が悪く、不要なようです。
// No garbage-collection-without-disposal issues
using (Font iconTitleFont = System.Drawing.SystemFonts.IconTitleFont)
{
using (FontFamily family = System.Drawing.FontFamily.GenericMonospace)
{
_TBTextBox.Font = new Font(family, iconTitleFont.SizeInPoints);
}
}
これらのクラスの静的メンバーのすべての使用は、最初にそれ自体が破棄されるローカル変数に割り当てる必要がありますか? もしそうなら、なぜですか?