question-mark
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.

BUG: GC.SuppressFinalize within any block (CC0029)

See original GitHub issue

public override void Dispose() { try { if (MyConnection != null) (MyConnection.Dispose(); } finally { GC.SuppressFinalize(this); } }

When you add a GC.SuppressFinalize (this) in a finally block the codecrack suggests the addition of SuppressFinalize method. I believe this is a small bug, or not?

code

Should work with any block too:

This should not raise a diagnostic:

public void Dispose()
{
    if (condition)
        GC.SuppressFinalize(this);
}

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
vs-krasnovcommented, Jul 6, 2016

@giggio @raphaelm22 May I work on this issue?

0reactions
giggiocommented, Aug 11, 2016

Closed on #819.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it harmless to call GC.SuppressFinalize within the finalizer?
The call to SuppressFinalize is actually quite trivial, it just sets a flag in the object to prevent it being added to the...
Read more >
CA1816: Call GC.SuppressFinalize correctly (code analysis)
In an unsealed class, a method that's an implementation of IDisposable.Dispose and doesn't call GC.SuppressFinalize.
Read more >
code-cracker/CHANGELOG.md at master
An analyzer library for C# and VB that uses Roslyn to produce refactorings, ... SuppressFinalize within any block (CC0029) #776; BUG: CC0052 (Make...
Read more >
C# static code analysis: "GC.SuppressFinalize" should not ...
GC.SuppressFinalize requests that the system not call the finalizer for the specified object. This should only be done when implementing Dispose as part...
Read more >
Can GC.SuppressFinalize cause performance problems?
SuppressFinalize(this) when your Dispose method has run. Otherwise the instance will not be garbage-collected easily, it will be queued on a ...
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found