We've been having some problems getting the PgSqlDataReaders to be shown as being disposed of correctly according to the scitech memory profiler. I have included what I'm doing below and I'll see thousands of PgSqlDataReaders shown as being garbage collected but not being disposed of.
private const int LoopTimes = 1000000;
public Form1()
{
InitializeComponent();
}
public PgSqlConnection GetConnection()
{
string connectionString = "Protocol=2";
PgSqlConnection newConnection = new PgSqlConnection(connectionString);
newConnection.ConnectionTimeout = 15;
newConnection.Database = "docs_charts";
newConnection.Host = "localhost";
newConnection.Password = "da_19_admin";
newConnection.UserId = "sw5user";
newConnection.Port = 5432;
newConnection.Open();
return newConnection;
}
public PgSqlCommand GetCommand(PgSqlConnection connection, string query)
{
PgSqlCommand command = new PgSqlCommand();
command.CommandText = query;
command.CommandType = CommandType.Text;
command.Connection = connection;
return command;
}
private void button1_Click(object sender, EventArgs e)
{
string query = "Select * From soapware_admin_providers";
for (int i = 0; i < LoopTimes; i++)
{
using (PgSqlConnection connection = GetConnection())
{
using (PgSqlCommand command = GetCommand(connection, query))
{
using (PgSqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection))
{
while (reader.Read())
{
reader.GetString(1);
reader.GetString(2);
reader.GetString(3);
}
}
}
}
}
}