Should a .Net/C# object call Dispose() on itself? -


below sample code written colleague. seems wrong me wanted check. should object call own dispose() method within 1 of own methods? seems me owner/creator of object should call dispose() when it's done object , not object itself.

it's .asmx web method calls dispose() on when it's done. (the fact it's web method incidental question in general.) in our code base instantiate web service classes within methods of other web services , call methods on them. if code call method, object toast when method returns , can't use object more.

[webmethod] public string mywebmethod() {     try     {         return dosomething();     }     catch(exception exception)     {         return string.empty;     }         {         dispose(true);     } } 

update: found few links related:

do need dispose web service reference in asp.net?

dispose web service proxy class?

for sure it's not prartice. caller should decide when finished using idisposable object, not object itself.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -