Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

1
vote
2answers
48 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: $...
0
votes
1answer
46 views

Should i use “using” inside event receiver

I'm confused if i should use the using statement inside an event because the event is "asynchronous" and the object can be disposed before ending the job. Or am i missing something public override ...
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 ...
0
votes
1answer
46 views

DocumentSet.Import and Detected use of SPRequest for previously closed SPWeb object

I've written a code to move DocumentSets from one list to another list and I'm talking about a lot of DocumentSets. And this has to happen in every Web and in every Site. I've written the following ...
2
votes
1answer
64 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 ...
3
votes
2answers
679 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 ...
0
votes
2answers
91 views

Dispose SPWeb error

I need an advice on sharepoint logs related to disposing objects. I was looking in the logs and found these : Unexpected Detected use of SPRequest for previously closed SPWeb object. Please close ...
0
votes
1answer
18 views

Getting SPWeb object disposal

I have following code like below: SPWeb web = SPContext.Current.Web; VariationLabel label = GetCurrentVariationLabel(web); return label; Can this cause memory leak?How would I dispose this web?...
1
vote
1answer
245 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 ...
0
votes
2answers
229 views

Disposing SharePoint Objects

If you open a SharePoint list like this var site = new SPSite(url); var web = site.OpenWeb(); var list = web.Lists["ListName"]; Is it OK to dispose site and web through properties of the list? var ...
0
votes
2answers
136 views

Dispose the correct SPSite object for garbage collection

I have these lines of code: string siteUrl = "http://myTestSite"; using (SPSite siteCollectionParent = new SPSite(strUrl)) { SPWebApplication webApplication = siteCollectionParent.WebApplication; ...
1
vote
1answer
311 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
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)) { ...
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 ...
0
votes
1answer
302 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
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
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. ...
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. ...
0
votes
0answers
132 views

SharePoint 2013 - disposing SP.ClientContext in JavaScript [duplicate]

I'm little bit confused about JS's COM in SharePoint 2013 and disposing ClientContext object. As far as I can see from earlier versions of SP (2010 mainly) you had to dispose ClientContext and ...
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 = ...
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 ...
4
votes
3answers
713 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 ...
0
votes
0answers
83 views

Event Reciever Object Disposal Issues

I am getting this error after adding a document to a library that has a custom event receiver associated with it: An SPRequest object was not disposed before the end of this thread. To avoid ...
0
votes
1answer
523 views

Do I need to dispose a SPWeb or SPSite object from a WorkflowContext

I'm working on a Custom Workflow activity. In the activity I use the WorkflowContext-object. From this object I get the current SPSite or SPWeb via the Site and Web properties of the WorkflowContext. ...
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 ...
1
vote
2answers
130 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 ...
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 = ...
0
votes
1answer
67 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
1answer
484 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 ...
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 ...
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 ...
0
votes
2answers
310 views

How to properly dispose of sp 2007 object in powershell?

First and foremost I've done A LOT of googling and even went past the first page or 2 :) so feel free to direct me to the proper post if necessary. I am trying to loop through a bunch of webs and ...
0
votes
1answer
167 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
1k 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 ...
2
votes
3answers
171 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
750 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. ...
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 ...
0
votes
1answer
654 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 ...
0
votes
1answer
463 views

Dispose SPWeb object in recursive function

I have updated my code as per suggestions from suggestions on my earlier question , I still see the error message for one of my recursive function. Below is the code snippet to recursively loop ...
0
votes
3answers
3k 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 ...
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 ...
0
votes
2answers
3k 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 = ...
2
votes
4answers
908 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
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?
0
votes
1answer
1k views

Proper use of SPWeb from SPContext for pulling lists

So, after about two hours on the subject I am thoroughly confused. There are viewpoints all over the place on how, when, and why to use Dispose() on SPWeb objects as they relate to SPContext. Can ...
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 ...
1
vote
1answer
653 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 ...
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
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 ...
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 ...