处置从函数返回的 SPWeb
我们的代码有时会从函数返回 SPWeb 对象。例如:
public SPWeb getDeptWeb()
{
SPWeb deptWeb = SpSite.OpenWeb(SpContext.Web.ID);
...
return deptWeb;
}
我们如何处理这个实例中的 SPWeb 对象?或者将其放置在我们接受返回参数的地方就足够了吗?
We have code where at times we'll be returning an SPWeb object from a function. So for example:
public SPWeb getDeptWeb()
{
SPWeb deptWeb = SpSite.OpenWeb(SpContext.Web.ID);
...
return deptWeb;
}
How can we dispose of the SPWeb object in this instance? Or is it sufficient to dispose it where we're accepting the returned parameter?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最好的方法可能是在调用者中处理
SPWeb
,例如使用 using 语句:The best way is probably to dispose of the
SPWeb
in the caller, e.g. with the using statement: