SharePoint foundation 2010 and SharePoint server 2010 object model contain objects that implement the IDisposable interface. Object disposal is very important in SharePoint.
What is Disposing Object?
Sharepoint foundation 2010 and sharepoint server 2010 object model contain objects that implement the IDisposable interface.
You should explicitly dispose those sharepoint objects that implements IDisposable when you are finished using them.
Why to dispose object in SharePoint?
SPSIte and SPWeb class objects are created as managed objects. However, these objects use unmanaged code and memory to perform their work. The manage part of the object is smaller than the unmanaged part.As smaller managed part does not put memory pressure, but large amount of unmanaged code can cause unusual behaviors.
So we should not rely on Garbage collector to release.
How to find incorrect Disposed objects?
- If system performs poor.
- If system crashes or user faces unexpected errors.
- In case your site is displaying unusual errors, there might be chance of memory leak due to incorrect dispose of objects.
- Instance of SPSIte and SPWeb contains a reference to an SPRequest object that in turn contains a reference to unmanaged object.