If you have a brush and pen as in:
Brush b = new SolidBrush(color);
Pen p = new Pen(b);
and dispose them like so:
b.Dispose();
p.Dispose();
How would you dispose it if it was:
Pen p = CreatePenFromColor(color)
which would create the brush and pen for you? I can't dispose the brush inside this method, right?
Is this a method not to be used with disposable objects?
EDIT: What I mean is, how do you dispose the BRUSH?
It is the job of the CreatePenFromColor method to dispose of the Brush instance. It's not obvious at a glance but if you dig into the implementation of the Pen class you will see that it does not hold onto the passed in Brush instance. Instead it just uses it to calculate a few values. So there's no reason for the Brush instance to live beyond the call to CreatePenFromColor and the method should be disposing of the instance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With