SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

With all the focus on disposing all disposable objects in SharePoint, I wondered if there is any harm in disposing an object twice. Especially since SharePoint seems to do some disposing itself too. You have to check if SharePoint will do your disposing, or you have to do it yourself.

I know you can wreck havoc by disposing the wrong object (e.g. SPContext.Current.Site).

share|improve this question
Yes, I know I answered my question directly after asking it, but it bugged my some time already and I couldn't find an answer here. Since all the focus is on calling dispose at the right places, I started wondering what would happen if you call dispose twice (or call it, when SharePoint will also dispose your object). – Dribbel Sep 23 '11 at 13:17
up vote 3 down vote accepted

After some research I found the answer on the general description page of the IDisposable-interface.

If an object's Dispose method is called more than once, the object must ignore all calls after the first one.

So, if you accidently dispose an SharePoint-object twice, no harm done.

share|improve this answer

I highly recommend that you download and install the SPDispose Check tool.

You have the option of including this as part of the build process inside of Visual Studio. I've found that it is helpful in finding things that were missed, but also it will point out when it does NOT need to be disposed. The errors also point to a specific error/note that you can then reference and learn the specific info for that case.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.