Table of Contents

Struct ObjectCollector

Namespace
Stride.Core
Assembly
Stride.Core.dll

A struct to collect objects implementing the IDisposable, or IReferencable interfaces, or pointers to memory allocated with Allocate(int, int), so they can be disposed in bulk at a later time.

public struct ObjectCollector : IDisposable
Implements
Inherited Members
Extension Methods

Properties

Count

Gets the number of elements collected to be disposed.

public readonly int Count { get; }

Property Value

int

Methods

Add<T>(T)

Adds an object implementing the IDisposable or IReferencable interfaces, or a nint to an object allocated using Allocate(int, int) to the list of the objects to dispose.

public T Add<T>(T objectToDispose) where T : notnull

Parameters

objectToDispose T

The object to add to the collector to be disposed at a later time.

Returns

T

Type Parameters

T

The type of the object to add.

Exceptions

ArgumentException

objectToDispose does not implement the interface IDisposable, IReferencable, and is not a valid memory pointer allocated by Allocate(int, int).

Dispose()

Disposes all the objects collected by this collector and clears the list. The collector can still be used for collecting.

public readonly void Dispose()

EnsureValid()

Ensures this collector is ready to be used for collecting object instances.

public void EnsureValid()

RemoveAndDispose<T>(ref T)

Removes an object from this collector and disposes it immediately, setting the reference to null.

public readonly void RemoveAndDispose<T>(ref T objectToDispose) where T : notnull

Parameters

objectToDispose T

The object to remove and dispose.

Type Parameters

T

Remove<T>(T)

Removes a disposable object from the list of the objects to dispose.

public readonly void Remove<T>(T objectToDispose) where T : notnull

Parameters

objectToDispose T

The object to be removed from the list of objects to dispose.

Type Parameters

T

The type of the object to remove.