Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Require GC.SuppressFinalize(this) when virtual dispose?

See original GitHub issue
public abstract class C : IDisposable
    public void Dispose()
        // Require GC.SuppressFinalize(this); here?

    protected virtual void Dispose(bool disposing)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

sharwellcommented, Jan 20, 2019

In the current Dispose pattern, the call to SuppressFinalize is required if you have a virtual Dispose method and the containing type (C in this case). It does not matter whether a user-defined finalizer is present.

The rule is not optional in this pattern so you do not need a configuration option to disable it. New guidance for IDisposable which removes this requirement as part of a broad simplification is in progress but not yet approved as a recommendation.

JohanLarssoncommented, Jan 21, 2019

We keep it as default warning for now then.

Read more comments on GitHub >

github_iconTop Results From Across the Web

When should I use GC.SuppressFinalize()?
In general, most any Dispose() method should be able to call GC.SupressFinalize() , because it should clean up everything that would be cleaned ......
Read more >
CA1816: Call GC.SuppressFinalize correctly (code analysis)
Dispose method is called, it frees resources of the object. This makes finalization unnecessary. IDisposable.Dispose should call GC.
Read more >
Be Careful Where You Put GC.SuppressFinalize - Alois Kraus
You should always call GC.SuppressFinalize from Dispose if you have a finalizer, not just when there is “a reason to finalize”, e.g. this.handle ......
Read more >
Dispose() methods should call GC.SuppressFinalize
List all Dispose() methods that do not call GC.SuppressFinalize(). This applies only for Dispose() method defined in classes which implement the ...
Read more >
CA1816: Call GC.SuppressFinalize correctly -- Redundant ...
Dispose () is not virtual. It is not possible for a derived type to correctly add the call to GC.SuppressFinalize , and it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found