Say you have a disposable type, e.g. MyDisposableType and create a generic list of such a type:
List
Now, suppose that you use your list and at some point you need to remove one of the items using RemoveAt. With disposable types, the correct sequence should be:
myList[ itemIndex ].Dispose( );
myList.RemoveAt( itemIndex );
This is easy to verify using the .NET CF Remote Perfomance Monitor and taking GC Heap snapshots and monitoring the instance numbers of Disposable types referred by MyDisposableType.
Niciun comentariu:
Trimiteți un comentariu