ODBC leaking memory in c# application

江枫思渺然 提交于 2019-12-11 21:26:53

问题


I've seem to have a memory leak. I found a post on stackoverflow recommending 'using' method but this doesn't seem to fix the issue.

I am using Red Gate memory profiler which shows an increase in unmanaged memory constantly rising.

This is the simple application I made to test:

namespace TimerDebug
{
public partial class TimerDebug : ServiceBase
{
    public TimerDebug()
    {
        InitializeComponent();
    }

    protected override void OnStart(string[] args)
    {
         // Create Timer
        Timer MyTimer = new Timer(500);
        MyTimer.Elapsed += MyTimer_Elapsed;

        // Start Timer
        MyTimer.Start();

    }

    void MyTimer_Elapsed(object sender, ElapsedEventArgs e)
    {
        using (var C = new OdbcConnection("Dsn=MyFireReport;"))
        {

            C.Open();

        }

        OdbcConnection.ReleaseObjectPool();
    }

    protected override void OnStop()
    {
    }
}
}

Does anybody know how to fix this? Thanks.


回答1:


OdbcConnection.ReleaseObjectPool(); is the cause of this. I had some serious problems with constantly increasing handles and memory leaks which caused the DEP to shutdown my software. The same problem can be observed with the analog in the SQLClient and even closing or disposing a connection before using this statement didn't helped.

I have left the OdbcConnection.ReleaseObjectPool(); to be used only in critical in my situation cases as destroyed connection to the Oracle server.

Currently I have removed these and the software is working stable for more than a week now.



来源:https://stackoverflow.com/questions/19090579/odbc-leaking-memory-in-c-sharp-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!