0

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.

Anonymous
  • 575
  • 1
  • 4
  • 11
  • I am using the Paradox database driver. – Anonymous Sep 30 '13 at 09:32
  • Have you tried placing `OdbcConnection.ReleaseObjectPool();` inside the `using` block ? – jbl Sep 30 '13 at 09:42
  • The idea is that the odbcconnection object only exists during the using statement, so placing the releaseobjectpool after ensures that the object has been disposed of and therefore closed, ready for release. – Anonymous Sep 30 '13 at 09:50
  • I'm trying what you suggested now, maybe making a difference. I'll let you know. – Anonymous Sep 30 '13 at 09:52
  • you are right. I guess including the ReleaseObjectPool in the using would require an explicit Close before it, which would be quite strange. Don't have any clue. Maybe this can be of some help is the paradox driver is as well written as the FM one http://stackoverflow.com/q/13513224/1236044 – jbl Sep 30 '13 at 09:59
  • Thanks for the link. Interesting tip about viewing handles in task manager. Mine seem ok but I spotted another developers app with a shed load - oops. I have thought about persistent connection or spawning a separate process each time. Oh well, looks like i will have to do that. Thanks for your input. – Anonymous Sep 30 '13 at 10:10
  • Monitoring my app now, without using the 'using' method - it seems to have stabalized at around 12mb private memory usage. Weird. Fingers crossed. – Anonymous Sep 30 '13 at 10:29

1 Answers1

0

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.

Serpiton
  • 3,676
  • 3
  • 24
  • 35