问题
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