I am seeing an issue with un-disposed SPRequest objects in the ULS logs when i work with content types in the object model.
My code is as follows (in previous methods run as part of this request, the library has been created using SPContext.Current.Web):
library.ContentTypesEnabled = true;
SPWeb web = library.ParentWeb;
SPContentTypeCollection contentTypes = web.AvailableContentTypes;
foreach (SPContentType contentType in contentTypes)
{
if (contentType.Group == "MyContentTypeGroup")
{
library.ContentTypes.Add((contentType));
}
}
In ULS I am seeing "An SPRequest object was reclaimed by the garbage collector instead of being explicitly freed" (1 for each content type that I add), the allocation stack trace points to the above code being the culprit:
at Microsoft.SharePoint.Library.SPRequest..ctor()
at Microsoft.SharePoint.SPGlobal.CreateSPRequestAndSetIdentity(SPSite site, String name, Boolean bNotGlobalAdminCode, String strUrl, Boolean bNotAddToContext, Byte[] UserToken, String userName, Boolean bIgnoreTokenTimeout, Boolean bAsAnonymous)
at Microsoft.SharePoint.SPWeb.InitializeSPRequest()
at Microsoft.SharePoint.SPListCollection.EnsureListsData(Guid webId, String strListName)
at Microsoft.SharePoint.SPListCollection.ItemByInternalName(String strInternalName, Boolean bThrowException)
at Microsoft.SharePoint.SPItemEventProperties.get_List()
at Microsoft.SharePoint.Taxonomy.TaxonomyItemEventReceiver.ItemAdding(SPItemEventProperties properties)
at Microsoft.SharePoint.SPEventManager.RunItemEventReceiver(SPItemEventReceiver receiver, SPUserCodeInfo userCodeInfo, SPItemEventProperties properties, SPEventContext context, String receiverData)
at Microsoft.SharePoint.SPEventManager.RunItemEventReceiverHelper(Object receiver, SPUserCodeInfo userCodeInfo, Object properties, SPEventContext context, String receiverData)
at Microsoft.SharePoint.SPEventManager.<>c_DisplayClassc`1.b_6()at Microsoft.SharePoint.SPSecurity.RunAsUser(SPUserToken userToken, Boolean bResetContext, WaitCallback code, Object param) at Microsoft.SharePoint.SPEventManager.InvokeEventReceivers[ReceiverType](SPUserToken
userToken, Guid tranLockerId, RunEventReceiver runEventReceiver, Object receivers, Object properties, Boolean checkCancel)
at Microsoft.SharePoint.SPEventManager.InvokeEventReceivers[ReceiverType](Byte[] userTokenBytes, Guid tranLockerId, RunEventReceiver runEventReceiver, Object receivers, Object properties, Boolean checkCancel)
at Microsoft.SharePoint.SPEventManager.ExecuteItemEventReceivers(Byte[]& userToken, Guid& tranLockerId, Object& receivers, ItemEventReceiverParams& itemEventParams, Object& changedFields, EventReceiverResult& eventResult, String& errorMessage)
at Microsoft.SharePoint.Library.SPRequestInternalClass.MoveUrl(String bstrUrl, String bstrWebRelOldUrl, String bstrWebRelNewUrl, Int32 grf)at Microsoft.SharePoint.Library.SPRequest.MoveUrl(String bstrUrl, String bstrWebRelOldUrl, String bstrWebRelNewUrl, Int32 grf) at Microsoft.SharePoint.SPFile.MoveCopyInternal(String strNewUrl, Int32 grf, Boolean requireWebFilePermission) at Microsoft.SharePoint.SPFile.CopyToFormsDir(String strNewUrl, Boolean keepNewerDestination) at Microsoft.SharePoint.SPContentTypeCollection.AddContentTypeToList(SPContentType
contentType)
at Microsoft.SharePoint.SPContentTypeCollection.AddContentType(SPContentType contentType, Boolean updateResourceFileProperty, Boolean checkName, Boolean setNextChildByte)
at Microsoft.SharePoint.SPContentTypeCollection.Add(SPContentType contentType)