Class NDBorrowedAttribute
- Namespace
- NumSharp
- Assembly
- NumSharp.dll
Marks a field, property, class or struct as borrowing the NDArray(s) it
references — they are owned and disposed by someone else — so the compile-time ownership
analyzer (NumSharp.Build.Analyzer) must not demand that the containing type dispose them.
[AttributeUsage(AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Property|AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
public sealed class NDBorrowedAttribute : Attribute
- Inheritance
-
NDBorrowedAttribute
- Inherited Members
Remarks
What the analyzer enforces without it. A type that STORES NDArrays — an
instance field or auto-property typed NDArray, an NDArray[], a tuple or
collection of NDArrays, an INDArrayCarrier result struct, or another type that
itself stores NDArrays (ownership is contagious) — owns their pooled buffers, so it must
implement IDisposable (or IAsyncDisposable) and dispose every
such member from its Dispose path. The analyzer reports NDW016 when the type is
not disposable at all and NDW017 for each storing member its Dispose never
reaches; and it treats an instance of such a disposable type like an NDArray in the per-method
leak pass (NDW012): constructing one and dropping it is a leak.
What this attribute asserts. On a member: the value it references is an
input the containing type was handed (a view over a caller's array, a shared lookup table, an
operand an iterator walks) — rule R2 of DISPOSAL-GUIDELINES.md, "never dispose an input
you were given" — so the member is excluded from the type's ownership set. On a type:
every NDArray the type references is borrowed, so the type is exempt from NDW016/
NDW017 outright and is never treated as an NDArray-owning value by NDW012, even
when it is disposable (a disposable that owns unmanaged state of its own but only borrows its
arrays — NumSharp's np.nditer is the archetype).
Runtime-inert, analyzer-only. Like NDScopedCoveredAttribute this
attribute changes nothing at runtime: nothing is woven, no scope is opened, nothing is disposed
or kept alive by it. It is the author's ownership statement, and a wrong one has the same
consequence as a wrong hand-written using: an array nobody disposes falls back to the
finalizer, or an array two owners dispose is freed under one of them. It never contains the
NDScopedAttribute/NDScopedAsyncAttribute names, so a project that uses only this
attribute draws no weaver-missing guard (NDW013).