SPWeb.Dispose Method

Releases all unmanaged resources that are used by the Web site object.

Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

<SharePointPermissionAttribute(SecurityAction.Demand, ObjectModel := True)> _
Public Sub Dispose

Dim instance As SPWeb

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

Implements

IDisposable.Dispose()

Remarks

Calling the Dispose method has the same effect as calling the Close method. Use the Dispose method to close the SPWeb 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 SPWeb 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 SPControl.GetContextWeb method, 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.

See Also

Reference

SPWeb Class

SPWeb Members

Microsoft.SharePoint Namespace

Other Resources

Best Practices: Using Disposable Windows SharePoint Services Objects