Informix memory leak

2019-07-02 16:33发布

问题:

I am running into an strange issue using Informix (specifically, I am using the IBM.Data.Informix namespace, 4.10 Client SDK). I am connecting to an IBM Informix database using ODBC and am running into memory leak issues. The documentation is fairly sparse, and I am locked into using the driver/SDK I currently have installed. Here is the code I am using for the database context:

public class IfxDbContext : IIfxDbContext
{
    private readonly string _connectionString;
    //private readonly IfxConnection _connection;

    public IfxDbContext(string connectionString)
    {
        _connectionString = connectionString;
        //IfxConnection conn = new IfxConnection(connectionString) {ConnectionString = connectionString};

        //_connection = conn;
    }

    public IEnumerable<Item> GetItems()
    {
        var items = new List<Item>();

        try
        {
            using (IfxConnection conn = new IfxConnection(_connectionString))
            {
                conn.Open();

                using (IfxCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "VALID SQL COMMAND";

                    IfxDataReader dr = cmd.ExecuteReader();

                    while (dr.Read())
                    {
                        //add to items
                    }
                }
            }
        }
        catch(IfxException ex)
        {

        }

        return items;
    }
}

}

I have tried disposing and closing any connection I can, but that doesn't seem to help. Am I missing something or is it an issue with the driver? The question then becomes, what can I do to free up memory incrementally? The app hits around ~1200 MB and crashes.

My particular errors are "Not enough space for parser stacks" and "Memory allocation failure".

Am I missing something?

回答1:

Turns out that this is an issue with the specific version of the SDK I am using for the project (4.10 - 32 bit). Unless you leave both the connection and the command open indefinitely, the application will leak memory. This isn't really a solution because there is a finite number of connections and that quickly runs out if I have multiple connections to the application. Because I need to continue using this specific SDK version, I configured IIS to recycle the app pool when it reached a memory threshold (1 GB in my instance). That resolved the issue for now, although it does nothing to address the underlying issue with the SDK.