title: Should a .Net/C# object call Dispose() on itself?
body: <p>Below is some sample code written by a colleague. This seems obviously wrong to me but I wanted to check. Should an object call its own <strong>Dispose()</strong> method from within one of its own methods? It seems to me that only the owner/creator of the object should call <strong>Dispose()</strong> when it's done with the object and not the object itself.</p>
  
  <p>It's an .asmx web method that calls <strong>Dispose()</strong> on itself when it's done. (The fact that it's a web method is probably incidental to the question in general.) In our code base we sometimes instantiate web service classes within methods of other web services and then call methods on them. If my code does that to call this method, the object is toast when the method returns and I can't really use the object any more.</p>
  
  <pre><code>[WebMethod]
  public string MyWebMethod()
  {
      try
      {
          return doSomething();
      }
      catch(Exception exception)
      {
          return string.Empty;
      }
      finally
      {
          Dispose(true);
      }
  }
  </code></pre>
  
  <p>UPDATE:
  Found a few links that are related:</p>
  
  <p><a href="https://stackoverflow.com/questions/429478/do-i-need-to-dispose-a-web-service-reference-in-asp-net">Do I need to dispose a web service reference in ASP.NET?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/2823695/dispose-a-web-service-proxy-class">Dispose a Web Service Proxy class?</a></p>