As of version 2023.3.0, it is not allowed to annotate struct types with attribute MustDisposeResource.
My example would be this:
[MustDisposeResource]
public struct ResourceToken<TResource> : IDisposable
where TResource : ResourceBase
{
private readonly ResourceManager _manager;
private readonly object lockObject = new();
private TResource _value;
private bool _disposed;
public ResourceToken(ResourceManager manager, TResource value) { ... }
public readonly TResource Value { ... }
public void Dispose()
{
if (_disposed) return;
lock (lockObject)
{
if (_disposed) return;
_manager.NotifyTokenDisposed(_value.InstanceId);
_value = null!;
_disposed = true;
}
}
}
This ResourceToken is used for reference tracking for loaded resources, so I could release resource when it is no longer in use by consumers. Token should be disposed, otherwise resource reference count will leak.
It is struct, and the attribute is valid only on properties, classes and fields.
As of version 2023.3.0, it is not allowed to annotate struct types with attribute MustDisposeResource.
My example would be this:
This ResourceToken is used for reference tracking for loaded resources, so I could release resource when it is no longer in use by consumers. Token should be disposed, otherwise resource reference count will leak. It is struct, and the attribute is valid only on properties, classes and fields.
Please allow using this attribute on structs.