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

Disposing using the protected virtual pattern does not seem to be detected. #65

Closed ericwra closed 7 years ago

ericwra commented 7 years ago

Prerequisites

Description

When using the protected virtual pattern for disposing, fields are detected as not disposed.

Source Code

     public class ExampleManager : IExampleService, IDisposable
     {
        private readonly _db;

        public ExampleManager() 
        {
            _db = new ExampleEntities(); // This is detected as not disposed.
        }

        private bool disposing;

        protected virtual void Dispose(bool disposing)
        {
            if (!disposing)
            {
                if (disposing)
                {
                    _db.Dispose();
                }

                //Dispose of unmanaged resouces here

                disposing = true;
            }
        }

        ~ExampleManager() {
           Dispose(false);
        }

        public void Dispose()
        {
            Dispose(true);
        }
    }
BADF00D commented 7 years ago

Will be part of release 0.33

ericwra commented 7 years ago

Perfect! Thank you for addressing my issues!