dotnet/runtime

Do not define finalizers in types derived from MemoryManager<T>

terrajobst opened this issue · 3 comments

Adding a finalizer to a type derived MemoryManager<T> is likely an indication of a bug, as it suggests a native resource that could have been handed out in a Span<T> is getting cleaned up and potentially while it's still in use by the Span<T>.

Category: Reliability

Estimates:

  • Analyzer: Small
  • Fixer: Not Applicable

Test scenarios:

  1. Type not derived from MemoryManager with or without finalizer should be OK
  2. Type derived from MemoryManager without finalizer should be OK
  3. Class directly derived from MemoryManager having finalizer should warn
  4. Class indirectly derived from MemoryManager having finalizer should warn

@bartonjs @terrajobst I have used warning level for severity and true for isEnabledByDefault please let me know if that is correct