1 / 20

Memory Management in SharePoint 2007 Development

Matt Vignau RJB Technical Consulting www.rjbtech.com matt.vignau@rjbtech.com. Memory Management in SharePoint 2007 Development. Overview. In C# .NET development we have the Garbage Collector No more destructors SPSite and SPWeb not always disposed Leaves growing used memory block

channary
Download Presentation

Memory Management in SharePoint 2007 Development

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Matt Vignau RJB Technical Consulting www.rjbtech.com matt.vignau@rjbtech.com Memory Management in SharePoint 2007 Development

  2. Overview • In C# .NET development we have the Garbage Collector • No more destructors • SPSite and SPWeb not always disposed • Leaves growing used memory block • Leads to problems

  3. Memory Leaks • Build with each use of the code • SPSite and SPWeb sites have ~2kB size wrappers • Object sizes are closer to 1-2 MB • One site with 15 webs accessed twice has used around 30 MB of system memory; for *one* user • Can bring down entire farms

  4. Example 1 • public void GetNavigationInfo() • { • SPWebOurWeb = http://intranet.litwareinc.com; • foreach(SPWebOurWebin OurWeb.GetSubWebsForCurrentUser()) •    { •       //Our Subsite code here •     } • }

  5. Memory Danger Signs • Does the application pool refresh frequently when under load? • Memory reset threshold 800 megs -1.5 gigs • Does the system perform poorly under heavy loads? • Does the entire system crash or users receive “Page not available”? • Does the system use custom webparts or third party webparts?

  6. Example 2 • public void GetNavigationInfo() • { • SPWebOurWeb= http://intranet.litwareinc.com; • foreach(SPWebOurWebin OurWeb.GetSubWebsForCurrentUser()) •       { •           //Our Subsite code here • OurWeb.Dispose(); •        } • }

  7. Example 3 pt 1 • try • { • SPSiteOurSiteObject; • SPWebOurObject; •     //our main code body here • }

  8. Example 3 pt 2 • catch • { •      //Our exception handling code • }

  9. Example 3 pt 3 • finally • { •      if(OurObject != NULL) •      { • OurObject.Dispose(); •      } •      if(OurSiteObject != NULL) •      { • OurSiteObject.Dispose(); •      } • }

  10. Breakdown • Try-catch block allows for exception handling • Finally block executes the dispose after the code block is complete to avoid problems • No explicit calls to dispose necessary for SPContext initializations

  11. Using statements • One of the most efficient means • Single block usage with automatic disposal • No additional call out to the dispose method is needed • Cannot use method outbound transfer of object beyond the using block

  12. Example 4 • using (SPWebOurWeb = null){ •                 //Our Code Here; • }

  13. Caching • Saves on memory • Improves access time • Is not thread-safe • IIS is multi-threaded • Best for single-user applications

  14. Example 5 • public void CacheData() • { • SPListItemCollectionoListItems; • oListItems = (SPListItemCollection)Cache["ListItemCacheName"]; •    if(oListItems == null) •    { • oListItems = DoQueryToReturnItems(); • Cache.Add("ListItemCacheName", oListItems, ..); •    } • }

  15. Example 6 • public void CacheData() • { • DataTableoDataTable; • SPListItemCollectionoListItems; •    lock(this) •    { • oDataTable = (DataTable)Cache["ListItemCacheName"]; •       if(oDataTable == null) •       { • oListItems = DoQueryToReturnItems(); • oDataTable = oListItems.GetDataTable(); • Cache.Add("ListItemCacheName", oDataTable, ..); •       } •    }

  16. Scalability • Target scale can impact performance considerations • Even with proper dispose, memory can grow • Projected concurrent users are a factor in your design

  17. Scale Questions Pt 1 • Is the data static, somewhat static (occasionally changes), or dynamic (often changes)? • Is the data the same for all users or does it change? (Dependent on user account, department within the company, etc) • Is the data easily accessible or does it require a long time to return the data?

  18. Scale Questions Pt 2 • Is the data public or does it require a higher level of security? • What is the size of the data? • Is the SharePoint site on a single server or on a server farm?

  19. Links • My Blog: http://blogs.rjbtech.com/MV/ • MSDN Best practices: http://msdn2.microsoft.com/en-us/library/aa973248.aspx# • Memory Pressure in MOSS: http://blogs.technet.com/stefan_gossner/archive/2007/11/26/dealing-with-memory-pressure-problems-in-moss-wss.aspx • Memory leak checking tool: http://blogs.rjbtech.com/RJB

  20. Questions? • Ask away!

More Related