Struct ObjectCollector
A struct to dispose IDisposable, IReferencable instances and allocated unmanaged memory.
public struct ObjectCollector : IDisposable
- Implements
- Inherited Members
- Extension Methods
Properties
Count
Gets the number of elements to dispose.
public int Count { get; }
Property Value
- int
The number of elements to dispose.
Methods
Add<T>(T)
Adds a IDisposable object or a nint allocated using AllocateMemory(int, int) to the list of the objects to dispose.
public T Add<T>(T objectToDispose)
Parameters
objectToDispose
TTo dispose.
Returns
- T
Type Parameters
T
Exceptions
- ArgumentException
If objectToDispose argument is not IDisposable or a valid memory pointer allocated by AllocateMemory(int, int)
Dispose()
Disposes all object collected by this class and clear the list. The collector can still be used for collecting.
public void Dispose()
Remarks
To completely dispose this instance and avoid further dispose, use Dispose() method instead.
EnsureValid()
public void EnsureValid()
RemoveAndDispose<T>(ref T)
Dispose a disposable object and set the reference to null. Removes this object from this instance..
public void RemoveAndDispose<T>(ref T objectToDispose)
Parameters
objectToDispose
TObject to dispose.
Type Parameters
T
Remove<T>(T)
Removes a disposable object to the list of the objects to dispose.
public void Remove<T>(T objectToDispose)
Parameters
objectToDispose
TTo dispose.
Type Parameters
T