Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在性能方面,使用单例模式在 WCF 中设计代理客户端,还是每次创建对象并在调用后关闭它会更好吗?
要看。我们最近遇到了这个问题,因为我们需要每隔几秒或更短的时间拨打一次电话,所以保留一个代理客户端实例并继续拨打电话更有意义。如果客户端/连接出现故障,我只是重新创建了代理客户端。
之前发生的事情是我每次调用都创建了一个新代理并关闭了连接。显然 GC 清理这些的速度不够快,内存在堆积。
我认为这取决于您调用该服务的频率。