0

I'm working with a WCF Client which looks like it's leaving String connection information in memory after an explicit close & the proxy going out of scope. The implementation I'm using is similar to this post:

Link to another stackoverflow discussion

I do the close on the Channel have confirmed it's not usable a second time. If I use DotMemory to analyze the memory I see 8 strings kept which look relative to the REST call mechanics. Retention objects look like this:

System.Net.TimerThread+TimerQueue ->
System.Net.TimerThread+TimerNode ->
System.Net.ConnectionGroup ->
System.Collections.ArrayList ->
System.Object[] ->
System.Net.Connection ->
System.Net.CoreResponseData ->
System.Net.WebHeaderCollection ->
System.String[] ->
System.String

The client I'm using to test this does almost nothing. A button which creates the proxy, uses it and then closes, my REST call works no problem.

using DotMemory Retention Path I see 2 paths which run through Timer:

System.Net.TimerThread+TimerQueue : Roots={Handle, Static reference }.m_Timers ->
System.Net.TimerThread+TimerNode.next ->
System.Net.TimerThread+TimerNode

Retention path of System.Net.TimerThread+Callback

System.Net.TimerThread+TimerQueue : Roots={Handle, Static reference }.m_Timers ->
System.Net.TimerThread+TimerNode.prev ->
System.Net.TimerThread+TimerNode.m_Callback ->
System.Net.TimerThread+Callback

If I want to figure out why the timer is in play, my guess is something weird is going on with the WebChannelFactory, maybe a default property I'm unaware of. This is just a straight REST call without any callback abilities.

Thanks for your patience, I'm a self taught C# person so please be gentle!

Community
  • 1
  • 1
  • What's the problem in keeping the strings in memory? Did you force a garbage collection? – CodeCaster Apr 05 '16 at 16:11
  • I used GC.Collect(). I realize it might not be a leak but just bad memory usage on my applications part, but if I .Close and allow the proxy to go out of scope, it can't do useful work again so I don't want it to consume resources however little. Having the static Timer reference holding that string information just perplexed me. – Frank Andrusiewicz Apr 05 '16 at 16:28

1 Answers1

0

Based on your retention path it looks like you're hitting the internal timer for closing service points.

This is controlled by System.Net.ServicePointManager.MaxServicePointIdleTime property and default value is 100 seconds.

So, you can either try to see if these strings disappear after you keep your application idle for 2 minutes or just set this timeout to something small (like 1 second) before calling your WCF client.

Igor Labutin
  • 1,406
  • 10
  • 10