For example:
Queue<System.Drawing.SolidBrush> brushQ = new Queue<System.Drawing.SolidBrush>();
...
brushQ.Clear();
If I don't explicitly dequeue each item and dispose of them individually, do the remaining items get disposed when calling Clear()? How about when the queue is garbage collected?
Assuming the answer is "no", then what is the best practice? Do you have to always iterate through the queue and dispose each item?
That can get ugly, especially if you have to try..finally around each dispose, in case one throws an exception.
Edit
So, it seems like the burden is on the user of a generic collection to know that, if the items are Disposable (meaning they are likely to be using unmanaged resources that won't be cleaned up by the garbage collector), then:
- When you remove an item from the collection, make sure you Dispose() it.
- DON'T CALL Clear(). Iterate through the collection and dispose of each item.
Maybe the documentation for the generic collections should mention that.