Brush recycling

I am having several memory issues with an application with a long lifespan; I studied drawing methods to ensure that the brushes are correctly positioned. In the case when Brusha brush is created in the function argument after a call?

The case is described below:

     g.DrawString(valueText, Font, new SolidBrush(Color.Red),
+5
source share
2 answers

I am not quite sure, but I do not believe that this is so. That would be safer:

using(var redBrush = new SolidBrush(Color.Red)
{
    g.DrawString(valueText, Font, redBrush);
}
+9
source

No, you have to do it manually. However, consider the classes Brushesand SystemBrushes, for ready-made brushes, which you can use without creating new ones (and you also don't need / don't need to manage).

+4
source

All Articles