BADF00D / DisposableFixer

This is a Visual Studio Extension and NuGet package that should identify and fix problems as memleaks while using IDisposables.
Other
35 stars 7 forks source link

Certain types that track disposables and therefore these disposables should be ignored #16

Closed BADF00D closed 7 years ago

BADF00D commented 7 years ago

There are certain types that track instances of IDisposables themself. If these instances are disposed, they automatically dispose the instance they keep track of. E.g the following code should not yield an diagnostics, because StreamReader disposed the given MemoryStream:

using System.IO;

namespace DisFixerTest.Tracking {
    internal class Tracking {
        public static void Do() {
            var mem = new MemoryStream();

            using (var tracking = new StreamReader(mem)) { }
        }
    }
}

On the other hand, in the folling code mem should be marked as not disposed.

using System;
using System.IO;

namespace DisFixerTest.Tracking {
    class NoneTracking : IDisposable {
        public static void Do() {
            var mem = new MemoryStream();

            using(var tracking = new NoneTracking(mem)) { }
        }

        public NoneTracking(IDisposable disp) {}

        public void Dispose() {
            throw new NotImplementedException();
        }
    }
}
BADF00D commented 7 years ago

Basically this bug got fixed by recent commits. But due to the fact that there is no configuration (all tracking types are hard-coded), this feature is pretty much useless. So next will be issue #15