C#应用程序中的ODBC泄漏内存 [英] ODBC leaking memory in c# application

查看:70
本文介绍了C#应用程序中的ODBC泄漏内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎有内存泄漏.我在stackoverflow上找到了一篇推荐使用"方法的帖子,但这似乎无法解决问题.

我正在使用Red Gate内存探查器,该探查器显示非托管内存的增加不断增加.

这是我要测试的简单应用程序:

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()
    {
    }
}
}

有人知道如何解决此问题吗? 谢谢.

解决方案

OdbcConnection.ReleaseObjectPool();是造成此问题的原因.随着句柄的不断增加和内存泄漏,我遇到了一些严重的问题,这些问题导致DEP关闭了我的软件. 在使用SQLClient进行模拟时,甚至在使用该语句没有帮助之前关闭或释放连接都可以观察到相同的问题.

我已将OdbcConnection.ReleaseObjectPool();留给我的情况下用于紧急情况,因为它与Oracle服务器的连接被破坏了.

目前,我已经删除了这些内容,并且该软件已经稳定运行了一个多星期.

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.

解决方案

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.

这篇关于C#应用程序中的ODBC泄漏内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆