G
Guest
Hello,
I'm using .NET Framework 1.1, C#. A couple of days before I've found out
that my application leaks memory not releasing objects with destructors. I'm
using some third-party components (Spring.NET and Oracle Data Provider .NET
(ODP.NET is actually a leak in my case)). I know that it's a good habit to
call Dispose() if the object is IDisposable, but in my case I cannot do this,
and need to rely on destructor (performance loss was considered).
Then I've tried to reproduce the problem in a small test project (with only
ODP.NET objects) and failed . The leak was away.
Now I suspect that Spring.NET/ODP.NET somehow blocks the finalizer thread,
so that it never clears the garbage left.
Justification:
/// <summary>
/// Create a new session
/// </summary>
/// <returns>The new session that can be used by the client.</returns>
public ISession CreateSession()
{
GC.Collect();
GC.WaitForPendingFinalizers(); //Application hangs here
GC.Collect();
GC.WaitForPendingFinalizers();
new Message(Message.MessageType.CalledCreateSessionOn0,
this.GetType().FullName).LogDebug();
ISession session = (ISession)
Application.CreateSession()[typeof(ISession).FullName+".Remote"];
return session;
}
This method will be called relatively early after the client starts (server
and client interact over normal MarshalByRef objects, there is anyway not
much interaction there...). It is practically the first client call on the
server side. Before the first client starts there will be some Spring.NET
initialization done and an OracleConnection opened and closed (to check that
the database is available).
The problem is that this code hangs on the first call to
GC.WaitForPendingFinalizers(). By "hangs" I mean that nothing else will be
done in application - no log messages, in Visual Studio I can pause/stop
application (shows me a Console.ReadLine(); line - is not relevant). I've
been waiting for 15 minutes - no changes. The memory leak was found out by
ANTS Profiler and is definitely there.
I've also installed WinDBG in order to find out where the finalizing thread
is blocked, but had not much advance on that field (starting from that I do
not know which of threads is finalizing thread).
I have source code for Spring.NET, but it is really huge and not quite
understandable. I would be happy if I'll find out that the problem is really
in Spring. Can anyone help me, please? Do I actually force the garbage
collector in a correct manner (Collect/WaitForFinalizers,
Collect/WaitForFinalizers)? How can I find out what the finalizing thread is
actually doing? Does the observed behaviour (hang on
WaitForPendingFinalizers) actually an evidence that there are problems in
finalizer?
Thank you in advance.
I'm using .NET Framework 1.1, C#. A couple of days before I've found out
that my application leaks memory not releasing objects with destructors. I'm
using some third-party components (Spring.NET and Oracle Data Provider .NET
(ODP.NET is actually a leak in my case)). I know that it's a good habit to
call Dispose() if the object is IDisposable, but in my case I cannot do this,
and need to rely on destructor (performance loss was considered).
Then I've tried to reproduce the problem in a small test project (with only
ODP.NET objects) and failed . The leak was away.
Now I suspect that Spring.NET/ODP.NET somehow blocks the finalizer thread,
so that it never clears the garbage left.
Justification:
/// <summary>
/// Create a new session
/// </summary>
/// <returns>The new session that can be used by the client.</returns>
public ISession CreateSession()
{
GC.Collect();
GC.WaitForPendingFinalizers(); //Application hangs here
GC.Collect();
GC.WaitForPendingFinalizers();
new Message(Message.MessageType.CalledCreateSessionOn0,
this.GetType().FullName).LogDebug();
ISession session = (ISession)
Application.CreateSession()[typeof(ISession).FullName+".Remote"];
return session;
}
This method will be called relatively early after the client starts (server
and client interact over normal MarshalByRef objects, there is anyway not
much interaction there...). It is practically the first client call on the
server side. Before the first client starts there will be some Spring.NET
initialization done and an OracleConnection opened and closed (to check that
the database is available).
The problem is that this code hangs on the first call to
GC.WaitForPendingFinalizers(). By "hangs" I mean that nothing else will be
done in application - no log messages, in Visual Studio I can pause/stop
application (shows me a Console.ReadLine(); line - is not relevant). I've
been waiting for 15 minutes - no changes. The memory leak was found out by
ANTS Profiler and is definitely there.
I've also installed WinDBG in order to find out where the finalizing thread
is blocked, but had not much advance on that field (starting from that I do
not know which of threads is finalizing thread).
I have source code for Spring.NET, but it is really huge and not quite
understandable. I would be happy if I'll find out that the problem is really
in Spring. Can anyone help me, please? Do I actually force the garbage
collector in a correct manner (Collect/WaitForFinalizers,
Collect/WaitForFinalizers)? How can I find out what the finalizing thread is
actually doing? Does the observed behaviour (hang on
WaitForPendingFinalizers) actually an evidence that there are problems in
finalizer?
Thank you in advance.