Should I dispose GDI+ object before its creation?
Is recommended to always Dispose GDI+ object after using it.
by e.g.
Pen p = new Pen(Color.Green);
// use 'p'
p.Dispose();
now, if I have this situation:
Pen p = new Pen(Color.Green);
// use green 'p'
p = new Pen(Color.Red); // Should I Dispose my 'p' first?
// use red 'p'
p.Dispose();
EDIT A:
Using 'USING' is not possible every time.
private Pen p;
public RefreshPen(style)
{
// p.Dispose(); +-
p = new Pen(style.Color);
// etc.
}
EDIT B:
Will this be OK?
using (Pen p = new Pen(Color.Green))
{
// use green 'p'
p = new Pen(Color.Red); // Should I Dispose my 'p' first?
// use red 'p'
p = new Pen(Color.Blue); // Should I Dispose my 'p' first?
// use blue 'p'
}