Memory leak in WCF (Duplex) on Server

时间秒杀一切 提交于 2019-12-13 12:08:15

问题


Hi have quite a problem with an Service running WCF in duplex-mode. It leaks memory (not much but it's about 80MB a day) and after having a memory-profiler running alongside the service for 24 hours I found most of the memory sitting in byte[] referenced by quite a mess but I most references end in something like this:

and the "root" looks like this:

I too see lots of ServiceChannel (around 200) comming (I think) from the callback-channels.

I'm rather sure that I only hold 1 of those for each of the connected clients.

Overall my problem seems to be almost the same as this: memory leak in silverlight Wcf implementation but on the server-side.

I even tried the [MTAThread] thing mentioned here: WCF service leaks handles and memory when a client times out but it just don't solve the problem.

I just don't think that the problem is with my code as I wrap the callback-channels after getting it with OperationContext.Current.GetCallbackChannel<IServiceConnectorCallback>() in one of my own objects and those don't leak (there is only one of those for each clients in memory at any given snapshot) - sure I reset those callbacks on several occasions as the channel might change (clients losing the connection or reconnecting) but I don't have a way of disposing the old references so I only drop them and the GC should do it's job on them.

I do use PerCall on my service so I don't have any handle to those objects in my code at all.

I really have no clue at how I can handle this aside from restarting the service every few days - a solution I don't want to probose right now :(

So please give me some help/hints on this - thank you very much!


回答1:


When a session based channel faults a call to Close will throw an exception. However, there are proxy side resources that are not cleaned up in this case and these are only cleaned up when you Abort the faulted channel

Make sure that when you replace a faulted channel that you Abort the old one first



来源:https://stackoverflow.com/questions/9373488/memory-leak-in-wcf-duplex-on-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!