DotNext by .NET Foundation and Contributors

<PackageReference Include="DotNext" Version="5.7.0" />

 SoftReference<T>

public sealed class SoftReference<T> : IOptionMonad<T>, ISupplier<object>, IFunctional<Func<object>>
Represents a form of weak reference which is eligible for garbage collection in Generation 2 only.

Gets state of the referenced object and referenced object itself.

public SoftReference(T target, SoftReferenceOptions options = null)

Initializes a new soft reference.

public static T op_Explicit(SoftReference<T> reference)

Gets the referenced object.

public static Optional<T> op_Explicit(SoftReference<T> reference)

Tries to retrieve the target object.

public void Clear()

Makes the referenced object available for garbage collection (if not referenced elsewhere).

public bool TryGetTarget(out T target)

Tries to retrieve the target object.

public Optional<T> TryGetTarget()

Tries to retrieve the target object.