Questions tagged [dispose]

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 not performed manually.

Filter by
Sorted by
Tagged with
42
votes
2answers
12k 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.
20
votes
1answer
1k 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 ...
11
votes
2answers
3k 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 ...
8
votes
3answers
5k 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 ...
7
votes
2answers
1k 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 ...
7
votes
3answers
4k 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
3answers
3k 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 ...
6
votes
1answer
16k 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 = ...
6
votes
2answers
565 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
2answers
2k 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
3answers
3k 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 ...
4
votes
3answers
715 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 ...
4
votes
5answers
4k 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, ...
3
votes
4answers
4k 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
2answers
2k 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: ...
3
votes
2answers
3k 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 ...
3
votes
1answer
51 views

What could be the impact on SP Farm from those errors?

I find the below error more frequently especially with the custom application pages that are developed. i saw approx 2000 of those errors in a hour span of ULS logs. What could be the impact on SP ...
3
votes
3answers
1k 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. ...
3
votes
3answers
1k 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 ...
3
votes
2answers
189 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
12k 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
702 views

SPAssignment and how to dispose correctly

I have been doing a lot of scripting lately and came across memory considerations recently as we are in the phase of running scripts in production environments. Basically what I do throughout my ...
3
votes
2answers
2k views

SharePoint 2013 Dispose checker

I've used SPDisposeCheck for SP2007/2010 and find it very useful for finding undisposed sp objects, but from this blog post, it's mentioned that it's no longer working for 2013. Is there any ...
3
votes
2answers
107 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
3answers
1k 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
4answers
910 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
93 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
172 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 = SPContext.Current....
2
votes
2answers
1k 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
754 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
149 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
134 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
67 views

Objects to be disposed in SharePoint

I am referring to the following link for disposing the SharePoint objects. Basically, I understand that mainly SPSite and SPWeb are the 2 objects that use unmanaged code. Best Practices: Using ...
2
votes
1answer
1k 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 = web....
2
votes
2answers
2k 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.
2
votes
1answer
360 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
4answers
701 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 OutputListField(GetList(...
1
vote
2answers
56 views

Powershell: When to call Dispose() on SPweb/SPSite variables?

I have been reading and I've found different approaches about when to use Dispose() I want to know if when using SharePoint 2016 Management Shell I will need to call it for the following cases: $...
1
vote
2answers
198 views

Code Review Question about disposing

Don't web.Dispose() dispose parent SPSite object? Is it Ok if I do this in web part? { SPSite site = SPContext.Current.Site; using (SPWeb web = site.OpenWeb(s)) { ...
1
vote
1answer
367 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
875 views

Memory Leak - Disposing SPSite and SPWeb?

So I read through another post here Disposal of SPWebs created using SPSite.OpenWeb(). Currently I only dispose of the SPSite object, and from my understanding whe SPSite disposes any opened SPWeb ...
1
vote
1answer
486 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 = SPContext.GetContext(...
1
vote
1answer
312 views

SPLimitedWebPartManager.Dispose() vs SPLimitedWebPartManager.Web.Dispose()

SPLimitedWebPartManager references SPWeb object internally and implements IDisposable interface, therefore we need to dispose it explicitly. As I understand, we need to dispose its internal SPweb ...
1
vote
1answer
746 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
654 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
251 views

SP Objects that need to be disposed [duplicate]

I know that we need to dispose of SPSite and SPWeb objects, especially in scenarios where we instantiate them or don't get them from context. Other than these, which other objects in the SP Object ...
1
vote
1answer
136 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
131 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
4answers
7k 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 ...