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

An anonymous undisposed variable is not marked as not disposed #108

Closed BADF00D closed 5 years ago

BADF00D commented 5 years ago

Prerequisites

Description

The sample code shows a new object creation (new SomeDisposable) and a factory method(CreateNew). The return type of the factory method get disposed, but the object creation does not. But the object creation is not marked as undisposed.

Source Code

using System;

namespace RxTimeoutTest
{
    internal class SomeClass
    {
        private IDisposable _field;

        public void Exchange() {
            using (var disposable = new SomeDisposable().CreateDisposable()) {
            }
        }
    }

    internal class SomeDisposable : IDisposable
    {
        public void Dispose()
        {
        }

        public SomeDisposable CreateDisposable()
        {
            return new SomeDisposable();
        }
    }
}

Screenshot

image