All Projects → BADF00D → DisposableFixer

BADF00D / DisposableFixer

Licence: other
This is a Visual Studio Extension and NuGet package that should identify and fix problems as memleaks while using IDisposables.

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to DisposableFixer

Asm Dude
Visual Studio extension for assembly syntax highlighting and code completion in assembly files and the disassembly window
Stars: ✭ 3,898 (+10435.14%)
Mutual labels:  visual-studio, visual-studio-extension
Encourage
A bit of encouragment added to Visual Studio
Stars: ✭ 69 (+86.49%)
Mutual labels:  visual-studio, visual-studio-extension
Vs Side Scroller
Scroll horizontally with the mouse wheel when holding the shift key in Visual Studio
Stars: ✭ 29 (-21.62%)
Mutual labels:  visual-studio, visual-studio-extension
VSMac-CodeCoverage
A Visual Studio for Mac code coverage extension.
Stars: ✭ 69 (+86.49%)
Mutual labels:  visual-studio, visual-studio-extension
Glyphfriend
Glyphfriend is a Visual Studio Extension to add previews for various icon/glyph fonts to Visual Studio.
Stars: ✭ 157 (+324.32%)
Mutual labels:  visual-studio, visual-studio-extension
OptionsSample
A Visual Studio extension sample
Stars: ✭ 14 (-62.16%)
Mutual labels:  visual-studio, visual-studio-extension
Openapi Connected Service
Visual Studio extension to generate OpenAPI (Swagger) web service reference.
Stars: ✭ 57 (+54.05%)
Mutual labels:  visual-studio, visual-studio-extension
XPathTools
A Visual Studio Extension which can run any XPath and XPath function; navigates through results at the click of a button. Can show and copy any XPath incl. XML namespaces, avoiding XML namespace induced headaches. Keeps track of the current XPath via the statusbar.
Stars: ✭ 40 (+8.11%)
Mutual labels:  visual-studio, visual-studio-extension
Micro Profiler
Cross-platform low-footprint realtime C/C++ Profiler
Stars: ✭ 123 (+232.43%)
Mutual labels:  visual-studio, visual-studio-extension
Google Cloud Visualstudio
Google Cloud Tools for Visual Studio
Stars: ✭ 80 (+116.22%)
Mutual labels:  visual-studio, visual-studio-extension
VS.DiffAllFiles
Visual Studio Extension to make comparing files before and after committing them to Git and TFS faster and easier.
Stars: ✭ 26 (-29.73%)
Mutual labels:  visual-studio, visual-studio-extension
D365FONinjaDevTools
To make of you a Ninja Developer in Dynamics 365 For Finance and Operations
Stars: ✭ 70 (+89.19%)
Mutual labels:  visual-studio, visual-studio-extension
TextTemplatingCore
T4 Text Templating with .NET Core
Stars: ✭ 24 (-35.14%)
Mutual labels:  visual-studio, visual-studio-extension
Structlayout
Visual Studio Extension for C++ struct memory layout visualization
Stars: ✭ 270 (+629.73%)
Mutual labels:  visual-studio, visual-studio-extension
Visual-Studio
A Discord Rich Presence extension for both Visual Studio 2017 and 2019.
Stars: ✭ 80 (+116.22%)
Mutual labels:  visual-studio, visual-studio-extension
Intrinsics Dude
Opensource Visual Studio extension for compiler instrinsics in C/C++
Stars: ✭ 44 (+18.92%)
Mutual labels:  visual-studio, visual-studio-extension
rudebuild
A non-intrusive bulk/unity C++ build tool for Visual Studio
Stars: ✭ 16 (-56.76%)
Mutual labels:  visual-studio, visual-studio-extension
unittestgenerator
A unit test generation extension for Visual Studio that aims to always produce code that compiles - covering the basic cases automatically and preparing as much as it can for the complex cases.
Stars: ✭ 32 (-13.51%)
Mutual labels:  visual-studio, visual-studio-extension
Discordrpcvs
An extension for Visual Studio 2017 that enables Discord Rich Presence.
Stars: ✭ 77 (+108.11%)
Mutual labels:  visual-studio, visual-studio-extension
Visual Studio Jquery Code Snippets
130+ jQuery code snippets for Visual Studio 2012-2019.
Stars: ✭ 250 (+575.68%)
Mutual labels:  visual-studio, visual-studio-extension
Visual Studio 2017 / Roslyn 2.x Visual Studio 2019 / Roslyn 3.x
Build Build status Build status
Tests AppVeyor tests (compact) AppVeyor tests (compact)
NuGet.org
Visual Studio Markedplace

DisposableFixer

This is a small Visual Studio Extension that should identify and fix problems as memleaks while using IDispoables. You can download it via Visual Studio Gallery or using Visual Studio Extension Manager.

Here is a little Preview of the extension in action:

Preview

This project is in early stage. Currently it has some known false positive and false negative results. Furthermore there are no code fixes available at the moment.

How It works

In order to check for undisposed IDispoables, there is an Roslyn analyser that registers for two syntax node actions:

  • ObjectCreation - something like new MemoryStream()
  • InvocationExpression - something like CreateMemoryStream()

Currently these both are considered the only possibilities where IDispoables can be created.

Every time one of the actions is triggered, the static code analyzer starts analyzing. The first thing the analyzer tries to find out is, whether the given expression created is actually an IDisposables. Otherwise the analysis is aborted. After that, the analyzer tries to find out, whether this IDisposable have to be disposed manually and if so, it checks if it is actually disposed, otherwise an diagnostics is reported.

When is a IDisposables considered as disposed?

Generally this extension assumes, that an IDisposable has to be disposed, where it gets created. The class that created an IDisposable is responsible for destroying it.

This sounds simple, but it's pretty complicated to detect, because this simple definition is not satisfied by all your code. Even within the code assemblies there are exceptions, that had to be detected correctly. In the following text, I want explain this in detail.

When is an anonymous and local variable considered as disposed?

These are variables, where the result of the ObjectCreation or InvocationExpression is not stored in a named variable, where it is created. Example:

public void SomeMethod(){
    new MemoryStream();
    //or
    var reader = new StreamReader(new MemoryStream());
    //or
    using(new MemoryStream()){}
}

Anonymous variables are considered disposed if:

  • A Dispose is called (e.g. new MemoryStream().Dispose())
  • It is used in a using (e.g. using(new MemoryStream()))
  • It is used as a parameter in the construction of a tracking type
  • It is used as parameter in a tracking method.
  • The source is a InvocationExpression and the source is a tracking factory. (not yet implemented)

WTF is that tracking stuff?

A tracking type is an IDisposable itself, that keeps track of the disposables given to this tracking type within the constructor. Example: System.IO.StreamReader. If you call new StreamReader(new MemoryStream()).Dispose() the anonymous StreamReader instance and the anonymous MemoryStream instance are both disposed, because the StreamReader keeps track of the given MemoryStream instance.

These situation are detected within the extension, because there is a configuration file that defines tracking types. Unfortunately this list is currently hard-coded an not yet editable by the user.

If you now notice, that there are certain constructor calls that does keep track of the given stream, then you are right. These situations are detected, too.

A tracking method is a method, that keeps track of an IDisposable. An Example is the following extension method from Reactive Extensions:

public void AddTo<T>(this T disposable, ICollection<IDispoable> disposables) where T : IDispoable

A tracking factory is a class that created IDisposables for your and it keeps track of these for you.

When is a field or property considered as disposed?

A field or property is considered disposed, if it gets disposed within a method that is named Dispose and has no parameters.

Plans for the future

There should be some way to configure the extensions. There is lots of configuration hard-coded within the extensions:

  • Tracking Types
  • Tracking Methods
  • Tracking Factory Methods
  • Ignored Interfaces/Types
  • Disposing Methods

Most of these pre-configured values are a good start for all projects. But sooner or later you will stuble upon a for instances tracking method of a private API you are using. These will unlikely became part of the extensions itself, but you should have a possiblity to configure these yourself.

Currenly there are three ideas:

  • The addtion of annotations (like JetBrains.Annotations for ReSharper)
  • Configurations per project via Addtional Files
  • A mixture of both preceeding ideas

Is there something that is not supported and will not be supported in future?

Renaming

If you rename a variable and call Dispose on the renamed variable. E.g.

var mem = new MemoryStream()
var mem2 = mem;
mem2.Dispose()

Some statisitics

Pull-Requests
Issues
Downloads Nuget
Contribution GitHub last commit GitHub contributors
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].