Skip to content

Port FxCop rule CA2000: DisposeObjectsBeforeLosingScope #476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ghost opened this issue Nov 21, 2015 · 12 comments
Closed

Port FxCop rule CA2000: DisposeObjectsBeforeLosingScope #476

ghost opened this issue Nov 21, 2015 · 12 comments

Comments

@ghost
Copy link

ghost commented Nov 21, 2015

Title: Dispose Objects Before Losing Scope

Description:

Because an exceptional event might occur that will prevent the finalizer of an object from running, the object should be explicitly disposed before all references to it are out of scope.

Dependency: Dataflow

Notes:

@srivatsn
Copy link
Contributor

Blocked on dataflow analysis

@alaforte
Copy link

I would be grateful if you will port this rule. Thank you

@tulandor
Copy link

Would be great to have this rule. Is there an update on the status of this?

@gafter
Copy link
Member

gafter commented Apr 25, 2017

CA2000 was implemented in the C# compiler as a proof of concept some time ago. We removed it from the compiler as the intent is to expand the scope of what analyzers can do to cover these kinds of use cases:

I believe our intent is that the IOperation APIs should eventually be capable of expressing this kind of rule. But we still have a long way to go before that is possible.

@mavasani
Copy link
Contributor

Need to ensure that issues mentioned in #1404 are addressed when this is implemented.

@jinujoseph jinujoseph modified the milestones: Unknown, 15.6 Nov 27, 2017
@mavasani mavasani self-assigned this Nov 27, 2017
@alaforte
Copy link

alaforte commented Nov 28, 2017 via email

@jinujoseph jinujoseph assigned ivanbasov and unassigned mavasani Jan 4, 2018
@drauch
Copy link

drauch commented Jan 29, 2018

What's the status on this one? : ) Since we've ported our projects to the new format we cannot use FxCop anymore - we still want to get warned when not disposing objects! Is there a workaround so that the compiler outputs a warning? Some kind of analyzer? At least a beta analyzer?

@sharwell
Copy link
Contributor

sharwell commented Jan 29, 2018

💡 In the meantime, the DotNetAnalyzers/IDisposableAnalyzers project by @JohanLarsson may provide the desired functionality.

@mavasani
Copy link
Contributor

@drauch We are currently working on preliminary DFA based experimental analyzer for dispose rules. We hope to have a beta package with the experimental DFA rules published in a few weeks.

@drauch
Copy link

drauch commented Jan 30, 2018

Thanks @sharwell , it looks really nice at first sight. I'll give it a try!

@mavasani
Copy link
Contributor

A PR for preliminary dataflow analysis based implementation of this rule is out for review: #1583

As mentioned in the PR, following are the TODOs to bring it to parity with original FxCop implementation:

  1. Analyze exceptional code paths (Analyze exceptional code paths in CA2000 (dispose objects before losing scope) #1580)
  2. Path sensitive analysis (Perform path sensitive analysis for dataflow based dispose rules #1581)
  3. Improve preciseness by moving to compiler CFG (Issues in preliminary DFA implementation due to lack of precise CFG #1567)

We hope to address these TODOs soon.

@jinujoseph jinujoseph modified the milestones: 15.6, 15.7 Feb 20, 2018
@mavasani
Copy link
Contributor

This rule has been implemented in the experimental DFA package. #1583 (comment) lists the TODO items, each of which are tracked with separate issues. Marking this issue as complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants