I’m learning to draw stuff in C# and I keep seeing recommendations to use dispose(), but I don’t quite understand what it does.
- When should I be using dispose() on a
code-drawn graphic? - What happens if I
don’t? - Do I need to call it every
time a graphic is not visible, such
as on a GUI that has tabs and the
user switched to the other tab, and
then redraw it when they switch back? - Will I break things if I call it when I shouldn’t?
- Will Batman escape the evil clutches of the Joker?
IDisposable, you should callDisposejust before it becomes eligible for garbage collection. As others have pointed out, it’s best to use theusingstatement instead of callingDisposedirectly.StreamWriter). For this reason, it’s best to always dispose any class that implementsIDisposable, as a general rule.Disposebefore you are done with the object, and then attempt to use the disposed object, you will get anObjectDisposedException.