Greetings, I have a C# windows form application with text and the font code is apparently auto generated and placed in the Form.Designer.cs file. I've been told that I need to ensure the font is disposed correctly but since it is auto generated code, I am unsure as to how to go about it. So, I searched and found this:
You can control the disposal of Font by including in using construct pattern. In the calling main, you should wrap the Application inside the using construct of the Form.
Example:
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FrmMainUtility());
to this:
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
using (FrmMainUtility form = new FrmMainUtility())
{
Application.Run(form);
}
Does this look correct to you? Is this a technique I can use to accomplish a clean disposal of the fonts?
I realize that there are Dispose methods that are standard practice, but I'd like to know if the above code works to dispose the fonts.
Note: My app has been subject to a HP Fortify scan. This example taken from :
http://stackoverflow.com/questions/21769908/how-and-when-is-font-disposed-for-winforms-controls[
^]