Zum Inhalt springen

Dispose pattern (ARCH1102)

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Key dotnet.resource.dispose-pattern · Severity warning · Category resource

If a class holds a disposable field, it is responsible for releasing that resource by implementing IDisposable itself. Otherwise the resource leaks.

public class ReportGenerator
{
private readonly SqlConnection _connection = new(Config.Conn);
}
public class ReportGenerator : IDisposable
{
private readonly SqlConnection _connection = new(Config.Conn);
public void Dispose() => _connection.Dispose();
}

Implement IDisposable on the class and release all owned disposable fields inside Dispose.