Dispose refers to the cleaning up of resources used by an object during its lifetime. The .NET Framework is a garbage-collected runtime, which means this happens automatically, however SharePoint has a habit of maintaining its unmanaged resources, which may result in high memory usage if disposal is ...

learn more… | top users | synonyms

26
votes
2answers
7k views

When to use OpenWeb() vs RootWeb

I am a little confused on the pro's and con's of each. When is it good to use OpenWeb() vs RootWeb, especially in the context of a using statement.
13
votes
1answer
649 views

Memory leak in Microsoft.Sharepoint.Taxonomy.TaxonomyItemEventReceivers?

I've been trying to locate some memory leaks we've noticed in our ULS (EventID: nask, An SPRequest object was not disposed ... etc). On my dev environment, and at least 2 other cleaner installs, the ...
11
votes
3answers
2k views

Should I dispose these SPSite and SPWeb objects?

Is it necessary to dispose the site and web objects in the following code? If so, how do I do this? Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load Dim site ...
9
votes
2answers
2k views

SPWeb being closed when getting list by powershell. What's wrong?

When I run this little piece of powershell code: $w = Get-SPWeb http://localhost $l = $w.List["some list"] I get Unexpected error message to my Sharepoint ULS log Detected use of SPRequest for ...
6
votes
2answers
905 views

Do you have to dispose of the SPWeb in the EventReceiver when using properties.OpenWeb()?

Does properties.OpenWeb() create a new SPRequest object or does it refer to the existing SPWeb object already there in the properties object? Should we manually dispose of the SPWeb obtained in this ...
6
votes
3answers
3k views

Disposal of SPWebs retrieved from SPContext.Current.Site.AllWebs

As there was a minor disagreement on whether SPWebs retrieved from SPContext.Current.Site.AllWebs should be disposed, I thought it would be appropriate to post a new question and discuss it here. I ...
6
votes
2answers
378 views

Is it bad to dispose an object twice?

With all the focus on disposing all disposable objects in SharePoint, I wondered if there is any harm in disposing an object twice. Especially since SharePoint seems to do some disposing itself too. ...
5
votes
3answers
2k views

Should I dispose SPWeb or SPList?

I am doing a whole bunch of things with one SPWeb and many SPLists. If I just dispose web in the finally section would that dispose all of SPLists that I instantiated? (btw, I understand the concept ...
5
votes
2answers
1k views

Will passing SPWeb as by value parameter cause a memory leak?

I have an issue in my SharePoint environment and I suspect that this code causes a memory leak. I'm passing a SPWeb object as a value parameter. Will the SPWeb object instance get disposed correctly ...
4
votes
5answers
3k views

Disposal of SPWebs created using SPSite.OpenWeb()

After reading some answers/comments on Disposal of SPWebs retrieved from SPContext.Current.Site.AllWebs, I opened up Reflector to dig deeper into the SPSite and SPWeb classes. I ran into a surprise, ...
4
votes
3answers
1k views

An SPRequest object was not disposed - determine where this object was allocated

I have the SPRequest object was not disposed error. 12/10/2013 14:21:03.03 w3wp.exe (0x260C) 0x1700 SharePoint Foundation Performance nask ...
3
votes
4answers
2k views

How to properly use the Using Statement with SharePoint Objects

What is best practice with the Using statement when working with SharePoint Objects. When and how should you use the Using statement, so objects used are disposed, etc?
3
votes
3answers
707 views

Dispose in Client Object Model

Should objects be disposed when using the client object model? If so, which ones? There seems to be plenty of information on this for server side, but nothing from Microsoft specifically about ...
3
votes
3answers
172 views

What is the correct way of disposing these webs

I've been trying to find documentation on how to correctly dispose webs and sites and I've come across this article which is quite good, but doesn't seem to cover all my scenarios. My specific ...
3
votes
2answers
147 views

Sharepoint 2013 Dispose in linq

I'm wondering if this needs to be disposed or if it's a bad method to get the title of a web. var currentWebApp = SPContext.Current.Site.WebApplication; IEnumerable<SPSite> allTeamSites = ...
3
votes
2answers
7k views

“Potentially excessive number of SPRequest objects” coming from Microsoft's own code?

In one of my SharePoint apps, I am getting this warning & stacktrace over and over (with different GUIDS): since it's only one of my apps, I assume there's something in my project's code, but ...
3
votes
2answers
79 views

Do I dispose the object?

I have been using SPDisposeChecker & reading through http://blogs.msdn.com/rogerla/archive/2008/02/12/sharepoint-2007-and-wss-3-0-dispose-patterns-by-example.aspx but there are some conditions I ...
2
votes
2answers
232 views

Does disposing SPSite dispose the SPWeb automatically?

Suppose we have code: CASE 1: using (SPSite site = new SPSite(SPContext.Current.Web.Url)) { SPWeb web = site.RootWeb; } Do we need to dispose the SPWeb in this case? CASE 2: ...
2
votes
3answers
826 views

SPDispose false positive

I got many warnings from the SPDispose checker like this: ID: SPDisposeCheckID_140 Module: xx.xx.dll Method: xx.xx.Layouts.xx.UpdateWorkspace.Page_Load(System.Object,System.EventArgs) Statement: ...
2
votes
2answers
2k views

Warning of undisposed objects in Microsoft's own SharePoint code

I found many 8l1n warnings of undisposed objects in the SharePoint ULS logs. The interesting thing is that the entire stack trace does not show anything in my code. I am not sure what to look for in ...
2
votes
4answers
604 views

What are the dangers of disposing of SPWeb when it's automatically disposed of?

In some cases such as: using (SPSite site = new SPSite(@"http://sitecollection/")) { SPWeb web = site.RootWeb; } you don't need to dispose of the SPWeb object because it is disposed of ...
2
votes
2answers
88 views

SPDisposeChecker, is this a false positive?

We have the following code: foreach (SPWeb website in collectionOfWebSites) { // Some code, no dispose of website } SPDisposeChecker is reporting it as a memory leak. Should ...
2
votes
3answers
96 views

To Dispose or Not to Dispose - IDisposable Passed as Function Parameter

If an IDisposable SharePoint object is passed into a function, does an explicit Dispose() call need to be made on it? Example: public void TheCallingFunction() { SPSite site = ...
2
votes
2answers
893 views

Dispose of SPItemEventProperties at the end of an event receiver?

Is there any need to call properties.Dispose(); at the end of an event receiver? Would this prevent memory leaks? Is this unnecessary? Is it best practice?
2
votes
2answers
342 views

Does SPWeb.Delete() Dispose of the object?

I recently got a comment on my Deleting a site with subsites programmatically article about properly disposing of SPWeb objects after they've been deleted: Don’t forget to dispose the deleted web. ...
2
votes
1answer
121 views

Will this code lead to an object not being disposed?

Say I have the following code: SPList promo1List = site.WebApplication.Sites[0].RootWeb.Lists.TryGetList("promotions"); Will this lead to the SPSite object Sites[0] not being disposed? I ran ...
2
votes
3answers
570 views

Disposing item.web

I have read this article and known which objects should be disposed. But I doubt whether oItem.Web returns the same object as spcontext.current.web object or it creates new one. If it creates new, I ...
2
votes
3answers
132 views

4 using statements looks messy? Any suggestions on what is a better way to code this?

Imagine the following code: using (SPSite spSite = new SPSite(this.SiteURL)) { using (SPWeb spWeb = spSite.OpenWeb()) { using (SPSite spSite2 = new SPSite(this.SiteURL2)) { ...
2
votes
1answer
943 views

Disposing of objects in an Event Receiver

I have an ItemUpdated event receiver running on a library. Some pretty basic logic. Here's the gist of what I'm doing: SPWeb web = properties.Web; SPContentTypeId ParentCT_Id = ...
2
votes
2answers
790 views

What tool to use to check memory leaks in SharePoint

Currently I encounter memory leaks in my SharePoint 2007 application. What is the best tool to identify is there any un-dispose objects in the codes? Example like DataTable, SPWeb, or SPList.
1
vote
4answers
678 views

Does this leak? SharePoint SPSite and SPList code

Would this code cause an SPList object to leak? It's enclosed in a Using statement but that's in a sub routine. String site = "http://server/sites/site"; foreach (string s in ...
1
vote
3answers
128 views

Can you provide a list of objects that needs to be disposed in SharePoint?

I need a list of SharePoint objects which need to be disposed. This is for code analysis purpose. I have got a code review today and want a quick list of the objects to look out for in the code.
1
vote
1answer
1k views

How to correctly dispose spweb and spsite on powershell foreach!

Title of the question is pretty simple, I have 18000 site collections and this script is showing 1GB of ram used, so I wonder how can I dispose correctly the spweb and spsite object $webapplication = ...
1
vote
1answer
634 views

Memory Leak - Disposing SPSite and SPWeb?

So I read through another post here http://www.sharepointoverflow.com/questions/1047/disposal-of-spwebs-created-using-spsite-openweb. Currently I only dispose of the SPSite object, and from my ...
1
vote
1answer
259 views

Implications of open SPWeb/SPSite

I have read in various places that un-disposed SPWeb/SPSite objects keeps valuable database connections open and large COM objects in memory. Not disposing those objects is like number one mistake ...
1
vote
1answer
469 views

Dispose SPContext.Web

Normally it is not required to dispose SPWeb when it is obtained from the current context. However what happens if I create the context on my own? SPContext spContext = ...
1
vote
1answer
127 views

Will searching SPWebApplication.Sites with Linq need to be diposed?

Situation: I only have the full URL of an image in our farm & no knowledge of where it comes from other than being in the web application so I need to locate the site/web/list/item segments. ...
1
vote
1answer
416 views

Dispose issue when working with content types

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 ...
1
vote
1answer
315 views

ParentWebId: Troubleshooting SPSite/SPWeb leaks in WSS v3 and MOSS 2007

Following the guidance below (1) to ensure that the stack trace of the allocation of the SPRequest object is preserved in memory and added to the ULS logs, I'm seeing a steady stream of 8l1n (High) ...
1
vote
1answer
130 views

How to properly dispose of SP objects although not assigned?

If I assign SPContext.Current.Site.OpenWeb().Title to a string, do I need to dispose of it (if possible)? string title = SPContext.Current.Site.OpenWeb().Title; I'm still a little fuzzy on when to ...
1
vote
2answers
74 views

When to call Dispose if passing SPContext.Site to a class library?

I'm just looking for a bit of sanity check on this one! I'm looking at many classes that have SPSite or SPWeb as a constructor for the class. The class is instantiated using SPContext.Site as the ...
0
votes
1answer
48 views

Will the code be leaking

I've wrote here a code for SharePoint 2007 to modify few items through out of all site collections in web app, my question is the code written good, or is there a leak somewhere, and i could improve ...
0
votes
4answers
3k views

Detected use of SPRequest for previously closed SPWeb object after SPQuery

this code run yesterday very well and today I've been trying to solve this error for hour now : Please close SPWeb objects when you are done with all objects obtained from them, but not before I ...
0
votes
3answers
1k views

SPSite and SPWeb object dispose inside foreach loop

I have a code that loops through all the Sites and Webs in a web application. My code uses for..each loop to navigate through each site and web object. I was wondering if we are required to dispose ...
0
votes
1answer
31 views

SPContext.Current.Web.ParentWeb needs disposing?

I am using SPContext.Current.Web.ParentWeb and I want to know if I have to dispose below: SPContext.Current.Web.ParentWeb
0
votes
2answers
2k views

best practice dispose parentWeb on feature activated, how to fix it in this scenario?

I am getting a warning from the spdisposecheck in one method I executed on the feature activated event. private void CopyAttendees(SPWeb currentWeb) { try { SPWeb parentWeb = ...
0
votes
1answer
264 views

PowerShell - Dispose SP Objects

I want to use PowerShell to loop through my SharePoint and dispose all objects properly. I don´t want to generate entrys in the SharePoint log like this: An SPRequest object was not disposed ...
0
votes
1answer
103 views

Could these errors be the cause of my timer job problem?

I have a timer job that runs every night at midnight. The first part of the timer job is to iterate through every single site in a particular site collection (there are many). The second part of the ...
0
votes
1answer
793 views

Detected use of SPRequest for previously closed SPWeb object

I've got an event receiver that fails, seemingly inconsistently. I've checked the ULS logs and I can see the 90hv Detected use of SPRequest for previously closed SPWeb object. Please close SPWeb ...
0
votes
1answer
556 views

“Detected use of SPRequest for previously closed SPWeb object” within Event receiver but no error when run in test harness

I have a very strange issue which I cannot explain. We have and event receiver and within this we instantiate our own class that does all the work we need it to do. As part of this we pass in an SPWEB ...