PgSqlDataReader not being disposed of

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
tomcat2001
Posts: 21
Joined: Wed 10 Sep 2008 20:29

PgSqlDataReader not being disposed of

Post by tomcat2001 » Wed 27 May 2009 13:37

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);
}
}
}
}
}
}

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Fri 29 May 2009 12:56

This is a designed behaviour caused by the internal implementation of dotConnect for PostgreSQL.

Post Reply