I'm a little confused about whether or not to dispose of image and icon resources when they are referenced by my forms. Specifically, whether there's a difference in behavior if I reference an image/icon from the design-time Resources or load the image at run time. (.Net4, VS2015, C#)
Obviously, if you set the Icon property of a form at design time to a Resource, you don't explicitly Dispose()
of it when the form is closing. But what about if you set it like this:
this.Icon = Resources.my_default_icon;
Do you have to dispose of this.Icon
upon closing that form?
Similarly, what if I have a mini-class just for "branding" and have a static Icon
object that gets loaded (possibly from a file, possibly just referencing the embedded Resource) at run time? Should I use a copy-constructor in that static Icon
's getter? Or is it OK to make it a public static Icon
and allow all my forms to have the following one-liner in their _Shown()
event?
this.Icon = MyBrandingClass.formIcon;
Not sure if it's very different, I have seen some references to setting a picturebox's image at run time and disposing of the Image, but would you dispose of an embedded Resource image? If I pass a reference to my branding image, can/should I omit the dispose? Or should I be using a copy-constructor in the getter to return a new Image object and then always dispose of it when done with the form?