本文介绍了InstanceContext持有的引用无法释放.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的Windows窗体客户端实现了回调合同,并使用双工通道与服务器通信.一切正常,除了程序完成后,我用来创建通道的InstanceContext仍然保留对回调对象的引用, 这是我的表格,因此,GC无法声明该内存.我尝试使用 OperationContext.Current
获取InstanceContext的引用,但它返回null.我做错了什么?
My windows form client implements a callback contract and uses a Duplex channel to talk to the sever. Everything works fine except that when my program finishes, the InstanceContext I used to create the channel still holds a reference to the callback object, which is my form and therefor, the GC cannot claim the memory. I tried to use theOperationContext.Current
to get reference of the InstanceContext but it returns null. What did I do wrong?
Feng
推荐答案
using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress))
{
serviceHost.Open();
OperationContext operationContext = OperationContext.Current;
InstanceContext instanceContext = operationContext.InstanceContext;
instanceContext.ReleaseServiceInstance();
}
谢谢.
这篇关于InstanceContext持有的引用无法释放.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!