2012-03-14 4 views
1

私が保守しているプロジェクトには、SPContextからSPWebとSPSiteオブジェクトがコンストラクタで初期化されている、たくさんのusercontrolがあります。これらのオブジェクトは、他のクラスに渡されます。これらのオブジェクトを処分する方法は?

public MyUserControl : UserControl 
{ 
private SPWeb web; 
public MyUserControl() { web = SPContext.Current.Web; } 
AnotherClass.SomeMethod (web); 
} 

ログには、次の2つのエントリで満たされています。

Detected use of SPRequest for previously closed SPWeb object. Please close SPWeb objects when you are done with all objects obtained from them, but not before. Stack trace: 
at Microsoft.SharePoint.SPListItemCollection.EnsureListItemsData()  
at Microsoft.SharePoint.SPListItemCollection.GetEnumerator()  
at XXXXXXXX.Web.UserControls.TopNavigation.LoadTopImage()  
at XXXXXXXX.Web.UserControls.TopNavigation.OnLoad(EventArgs e)  
at System.Web.UI.Control.LoadRecursive()  
at System.Web.UI.Control.LoadRecursive()  
at System.Web.UI.Control.LoadRecursive()  
at System.Web.UI.Control.LoadRecursive()  
at System.Web.UI.Control.LoadRecursive()  
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)  
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)  
at System.Web.UI.Page.ProcessRequest()  
at System.Web.UI.Page.ProcessRequest(HttpContext context)  
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()  
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)  
at System.Web.HttpApplication.PipelineStepManager.ResumeSteps(Exception error)  
at System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext context, AsyncCallback cb)  
at System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context)  
at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr managedHttpContext, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)  
at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr managedHttpContext, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)  
at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr managedHttpContext, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)  
at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr managedHttpContext, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags) 

2)

An SPRequest object was not disposed before the end of this thread. 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. This object will now be disposed. Allocation Id: {444DCCA1-C2F6-493D-9D02-D04F75C6E384} This SPRequest was allocated 
at 
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.SPWeb.InitWebPublic()  
at Microsoft.SharePoint.SPWeb.get_LanguageCulture()  
at Microsoft.SharePoint.SPWeb.get_Title()  
at XXXXXXXXX.DataAccessUtility.<>c__DisplayClassc.<GetSitesTopNav>b__8()  
at Microsoft.SharePoint.SPSecurity.<>c__DisplayClass4.<RunWithElevatedPrivileges>b__2()  
at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode)  
at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param)  
at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode)  
at XXXXXXXX.GetSitesTopNav(SPSite site, SPWeb Currentweb, String userName)  
at XXXXXXXX.Web.UserControls.TopNavigation.PopulateSiteSelection()  
at XXXXXXXX.Web.UserControls.TopNavigation.OnLoad(EventArgs e)  
at System.Web.UI.Control.LoadRecursive()  
at System.Web.UI.Control.LoadRecursive()  
at System.Web.UI.Control.LoadRecursive()  
at System.Web.UI.Control.LoadRecursive()  
at System.Web.UI.Control.LoadRecursive()  
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)  
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)  
at System.Web.UI.Page.ProcessRequest()  
at System.Web.UI.Page.ProcessRequest(HttpContext context)  
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()  
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)  
at System.Web.HttpApplication.PipelineStepManager.ResumeSteps(Exception error)  
at System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext context, AsyncCallback cb)  
at System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context)  
at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr managedHttpContext, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)  
at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr managedHttpContext, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)  
at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr managedHttpContext, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)  
at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr managedHttpContext, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags) 

1)

がSPContext.Current.Webから取得したURLを渡しています.Url正しい方法?助言がありますか?

答えて

0

は、このMSDNフォーラムのリンクをお試しください - http://social.msdn.microsoft.com/Forums/et-EE/sharepoint2010general/thread/5ca4659a-d89d-44b1-9729-21854d715c7d

PS - 返信があなたを助けている場合の答えとしてこれをマークしてください。

+0

Roger Lambのこのブログは、共有オブジェクトモデルのdisposeパターンを理解する必要がある場合に役立ちます。 http://blogs.msdn.com/b/rogerla/archive/2008/02/12/sharepoint-2007-and-wss-3-0-dispose-patterns-by-example.aspx – bkk

関連する問題