配置一个Web服务代理类? [英] Dispose a Web Service Proxy class?
问题描述
当您创建并在ASP.Net框架使用Web服务代理类,该类最终从组件,它实现了IDisposable继承。
When you create and use a Web Service proxy class in the ASP.Net framework, the class ultimately inherits from Component, which implements IDisposable.
我从来没有见过一个例子网上,人们处理Web代理类,但不知道是否真的需要做的事情。当我打电话只有一个方法,我通常将它包装在using语句,但是如果我有需要调用它在整个页面几次,我可能最终会使用相同的实例,而只是想知道是什么后果都没有处置吧。
I have never seen one example online where people dispose of a web proxy class, but was wondering if it really needs to be done. When I call only one method, I normally wrap it in a using statement, but if I have a need to call it several times throughout the page, I might end up using the same instance, and just wondered what the ramifications are of not disposing it.
推荐答案
您需要处置的所有的实现的IDisposable
。
的IDisposable
的实施表示该对象保存到的的东西的垃圾收集不内在轨迹 - 可能是一个连接,可能是一个文件,可能是一些其他的手柄 - 或者可能是什么都没有,这并不重要。你不应该使用的实施细则担心自己因为这些有可能发生变化。
The implementation of IDisposable
signifies that the object holds onto something that the garbage collector doesn't intrinsically track - might be a connection, might be a file, might be some other handle - or might be nothing at all, it doesn't really matter. You shouldn't concern yourself with the implementation details because those are subject to change.
类可以或可以不真正使用非托管资源。它可以或可以不具有一个终结。这差别不大;如果该类实现的IDisposable
,那么它要求你的Dispose
它时,你就大功告成了。即使的Dispose
方法不做任何事,你永远不知道什么时候有人会用一个子类,真正的引用更换引用该类确实的需要以设置
The class may or may not truly use unmanaged resources. It may or may not have a finalizer. It makes little difference; if the class implements IDisposable
, then it's asking you to Dispose
it when you're done. Even if the Dispose
method does nothing, you never know when somebody will replace the reference to that class with a reference to a subclass that really does need to be disposed.
这篇关于配置一个Web服务代理类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!