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

Addition to #70: Call to Close on can be seen as calls to Dispose #83

Closed BADF00D closed 6 years ago

BADF00D commented 6 years ago

Prerequisites

Description

In addition to SerialPort, there are more classes where a call to Close can be recognized, as if it was a call to Dispose:

Source Code

SqlConnection connection = null;
SqlCommand command = null;
SqlDataReader reader = null;
try
{
    connection = new SqlConnection(connectionString);
    await connection.OpenAsync();

    command = connection.CreateCommand();
    command.Connection = connection;
    command.CommandText = "";
    command.CommandType = CommandType.Text;
    stopWatch.Start();
    reader = await command.ExecuteReaderAsync(); // << warning!!!
    stopWatch.Stop();
    LoggerHelper.LogStress("LoadCustomerInformations", "SELECT [Name]", stopWatch.Elapsed, "");
    stopWatch.Restart();
    while (await reader.ReadAsync())
    {
        customerInformations.Add(new KeyValuePair<string, string>((string)reader["Name"], (string)reader["ConnectionString"]));
    }
    LoggerHelper.LogStress("LoadCustomerInformations", null, stopWatch.Elapsed, "");
}
finally
{
    reader?.Close();
    connection?.Dispose();
    command?.Dispose();
}

Screenshot

BADF00D commented 6 years ago

Will be part of next release (probably 1.0.1)

xperiandri commented 6 years ago

Cool! Thanks!

BADF00D commented 6 years ago

@xperiandri Just uploaded version 1.0.1. Should be available soon.