Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
SDK Documentation
SPSite Class
SPSite Methods
 Dispose Method

  Switch on low bandwidth view
Community Content
In this section
Statistics Annotations (0)
SPSite.Dispose Method (Microsoft.SharePoint)
Releases all unmanaged resources that are used by the site collection object.

Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)
Visual Basic (Declaration)
<SharePointPermissionAttribute(SecurityAction.Demand, ObjectModel:=True)> _
Public Sub Dispose
Visual Basic (Usage)
Dim instance As SPSite

instance.Dispose
C#
[SharePointPermissionAttribute(SecurityAction.Demand, ObjectModel=true)] 
public void Dispose ()

Calling the Dispose method has the same effect as calling the Close method. Use the Dispose method to close the SPSite object and release resources when you are finished using the object. Do not reuse the object or objects that are obtained through the object after it is closed.

If you create an SPSite object, you can use the Dispose method to close the object. However, if you have a reference to a shared resource, such as when the object is provided by the GetContextSite method or Site property (for example, SPContext.Current.Site), do not use the Dispose method to close the object, but instead allow Windows SharePoint Services or your portal application to manage the object. For more information about object disposal, see Best Practices: Using Disposable Windows SharePoint Services Objects.

The following code example shows how to use the Dispose method.

C#
SPSite oSiteCollection = new SPSite("http://" + 
    System.Environment.MachineName + "/sites/Site_Collection");
...
oSiteCollection.Dispose();
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker