There are several different ways of retrieving an SPWeb object.
Take the following 3 examples:
1) SPContext
SPWeb web = SPContext.Current.Web
2) OpenWeb
SPSite site = new Site("http://myserver/");
SPWeb web = site.OpenWeb("");
3) Site "RootWeb"
SPSite site = new Site("http://myserver/");
SPWeb web = site.RootWeb;
Thumb rule:
- Never dispose SPContext.Current.Web or SPSite.RootWeb
- Make sure you dispose of [OpenWeb("")] objects and [new Site("")/new Web("")] objects
As for [OpenWeb("")] and [new Site("")/new Web("")]objects, if not disposed, applies heavy penalty on system memory.
Hope this helps.
Cheers
No comments:
Post a Comment