Tuesday, August 20, 2013

Why Dispose SharePoint Object ?

We usually don't take care much about disposing the objects explicitly in Asp.net application , as it is taken care by the Garbage Collector itself.As SharePoint itself is built on top of the .net Platform , then why it is always recommended to dispose the SharePoint Object !

In true sense most of the SharePoint Foundation objects, primarily the SPSite class and SPWeb class objects, are created as managed objects.
 However, these objects use unmanaged code and memory to perform the majority of their work. The managed part of the object is much smaller than the unmanaged part.
Because the smaller managed part does not put memory pressure on the garbage collector, the garbage collector does not release the object from memory in a timely manner.
The object's use of a large amount of unmanaged memory can cause the unusual behaviors specified below :

  • High memory use for Internet Information Services (IIS) worker processes
  • Poor system and application performance 
  • Frequent recycles of the SharePoint Foundation application pool, especially during peak usage
  • Application crashes that appear as heap corruption in the debugger
Calling applications that work with IDisposable objects in SharePoint Foundation must dispose the objects when the applications finish using them. We should not rely on the garbage collector to release them from memory automatically. 

Thursday, January 17, 2013

Compare Two SharePoint DateTime Control Javascript

 Event Starts :  <SharePoint:DateTimeControl ID="dtEventStarts" LocaleId="2057"   runat="server" />                            
 Event Ends :   <SharePoint:DateTimeControl ID="dtEventEnds" LocaleId="2057"  runat="server" />
 //Compare the start date and End Date of without recurrance patter
 function validatePlainStartDateAndEndDatePattern(source, args) 
            var chkEventRepeatsControl = document.getElementById('<%= chkEventRepeats.ClientID %>');         //get the check box value for testing event is recurrence or not
            if (!chkEventRepeatsControl.checked)
                var eventStartDateString = document.getElementById('<%=dtEventStarts.Controls[0].ClientID%>').value;            
                var startdateDTA = eventStartDateString.split("/");
                var actStartDate = new Date(startdateDTA[2], startdateDTA[1], startdateDTA[0], (document.getElementById('<%=dtEventStarts.Controls[1].ClientID%>').value).replace(":", ""), document.getElementById('<%=dtEventStarts.Controls[2].ClientID%>').value);

                var eventEndDateString = document.getElementById('<%=dtEventEnds.Controls[0].ClientID%>').value;
                var EndDateDTA = eventEndDateString.split("/");
                var actEndDate = new Date(EndDateDTA[2], EndDateDTA[1], EndDateDTA[0], (document.getElementById('<%=dtEventEnds.Controls[1].ClientID%>').value).replace(":", ""), document.getElementById('<%=dtEventEnds.Controls[2].ClientID%>').value);
                if (actStartDate.getTime() < actEndDate.getTime())
                    args.IsValid = true;
                    args.IsValid = false;