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

Problem with non disposed disposables inside a using block #27

Closed BADF00D closed 7 years ago

BADF00D commented 7 years ago

All these MemoryStreamCreations inside the using block should be marked as not disposed, like the second example shows. image

BADF00D commented 7 years ago

All three MemoryStreams should be marked as not disposed.

using System;
using System.IO;

namespace DisFixerTest.ObjectCreation {
    class ObjectCreationInUsingBlock {
        public ObjectCreationInUsingBlock() {
            using(var memStream = new MemoryStream()) 
            {
                new MemoryStream(); //this should be marked as not disposed
                var tmp = new MemoryStream(); //this should be marked as not disposed
                var tmp2 = Create();//this should be marked as not disposed
            }
        }
        private IDisposable Create() {
            return new MemoryStream();
        }
    }
}