This session covers the unmanaged world of SharePoint.
Internally, most of the things done in SharePoint using either the UI, the object model or web services, are done through unmanaged code. To be more specific: web Parts, web services and other objects in SharePoint are layers over the unmanaged code, and the object model is a wrapper that calls the unmanaged code.
This session explains what is the SharePoint unmanaged code, what are the internals of the unmanaged code and how exactly it works with the object model.
An example on the use of the owssvr.dll (principal dll of the unmanaged code) is also presented.
Some unmanaged code internals are a must know for SharePoint developers.
Understanding how our managed code works, will help us to write better code, troubleshoot, and design solutions in a better way.
7. Managed Code: It compiles to Intermediate Language (IL). It runs and is managed by the CLR. The runtime provides services such as security, memory management, threading, etc. Unmanaged Code: It compiles directly to machine code. It does not run and is not managed by the CLR. It doesn't get the services of the runtime. Unmanaged code vs Managed code
8. For an understanding of how things work: OM is a wrapper of the unmanaged code. The managed part is small; the unmanaged part of is much larger. Understanding will help us to: Troubleshoot issues, fix bugs and do performance tuning. Write scalable, quality and solid code. Avoid memory issues and poor performance. Why should I care?
12. Potentially excessive number of SPRequest objects (9) currently unreleased on thread 6. Ensure that this object or its parent (such as an SPWeb or SPSite) is being properly disposed. This object is holding on to a separate native heap. Common Issues
13. An SPRequest object was reclaimed by the garbage collector instead of being explicitly freed. To avoid wasting system resources, dispose of this object or its parent (such as an SPSite or SPWeb) as soon as you are done using it. Allocation Id: {6E0B2F08-BEE0-43D4-BEDA-FDA2A43F40D8} To determine where this object was allocated, create a registry key at HKEY_LOCAL_MACHINEOFTWAREicrosofthared Toolseb Server ExtensionseapSettings. Then create a new DWORD named SPRequestStackTrace with the value 1 under this key. Common Issues
14. Disposing objects Using objects efficiently Performance concerns – Memory allocation Write scalable code Unmanaged Code: Best Practices
15. Caching Objects that contain an embedded reference to SPWeb or SPSite objects. SPWeb and SPSite contain reference to unmanaged code (not thread safety) and should not be cached. Using objects efficiently
19. Always ensure to correctly dispose all SPWeb and SPSite. Dispose all objects implementing the IDisposable interface . Object disposal: Dispose method; using clause; try, catch, and finally blocks. SPDisposeCheck, free tool that inspects your assemblies for coding practices that cause memory leaks because of improper handling and disposal of SharePoint objects. Disposing SharePoint Objects
23. Performance concerns – Memory allocation How many SPRequest objects are open in parallel? Do SPRequest objects still exist at the end of the thread that created it?
25. The principal DLL of the unmanaged code is owssvr.dll OWSSVR.DLL is an ISAPI extension registered in IIS and its methods can be called directly via an HTTP request to /_vti_bin/owssvr.dll. Returning all data for a SharePoint list, including its XSD:http://WebApp/[site]/_vti_bin/owssvr.dll?Cmd=Display&List={ListGuid}&Query=*&XMLDATA=TRUE Owssvr.dll
28. SharePoint executes all the read/write operations to the DB through unmanaged code. SPWeb and SPSite contain a reference to the unmanaged code. Unmanaged objects are created in form of a SPRequest. Because SPRequest does not run under the .NET Runtime, we have to dispose those objects to avoid memory issues. Summary