Garbage Collection :D a feature in .NET http://msdn.microsoft.com/en-us/magazine/bb985010.aspx
In essence it sits in the back end and tracks objects and disposes of them in the back end on a schedule/when needed (not too sure on when it runs, its been awhile). However its limited to managed code. -DB From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of Paul Noone Sent: Thursday, 23 February 2012 11:20 AM To: 'ozMOSS' Subject: RE: At your Disposal Fine, Ill bite. Whats GC stand for?? :D From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of Daniel Brown Sent: Thursday, 23 February 2012 11:22 AM To: 'ozMOSS' Subject: RE: At your Disposal Side Tracking a little: Ø Brian Said: you need to dispose of stuff you create yourself Ah, Back in an older language (C) before garbage disposal, this was the norm :P malloc <http://msdn.microsoft.com/en-us/library/6ewkz86d%28v=vs.80%29.aspx> () & free <http://msdn.microsoft.com/en-us/library/we1whae7%28v=VS.71%29.aspx> () ! Destroy what you create! This also applies for APIs. Which at the heart of the issue, is exactly why Dispose needs to be called with the SharePoint API as GC will not always get all objects from unmanaged code, which in the deep back end, there is a substantial amount. -DB From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of Brian Farnhill Sent: Thursday, 23 February 2012 10:24 AM To: 'ozMOSS' Subject: RE: At your Disposal No it doesnt you need to dispose of stuff you create yourself. The only exception that that is when you create an SPSite yourself you can get the RootWeb property without having to dispose of it, but anything that comes from OpenWeb will need to be disposed of. SPDisposeCheck does a good job at picking all that sort of stuff up. As for the context yes if your web part will only be dealing with objects in the current context (eg. Both site and current user) then by all means use it. You can at least grab the SPSite from context and then open up webs within the site collection and then thats one less thing to dispose of. Brian Farnhill Solutions Architect, Extelligent Design | SharePoint Server MVP phone: 0408 289 303 | twitter: <http://twitter.com/BrianFarnhill> @BrianFarnhill | blog: <http://blog.brianfarnhill.com/> blog.brianfarnhill.com | xbox: <http://live.xbox.com/en-AU/MyXbox/Profile?Gamertag=Modern%20Bogan> Modern Bogan From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of Paul Noone Sent: Thursday, 23 February 2012 10:50 AM To: 'ozMOSS' Subject: RE: At your Disposal But surely disposing of the site via the using statement would include any sub webs?? And why not just use SPContext to get the web anyway? I keep trying to find best practice code examples to learn from and just wind up more confounded than when I started. From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of Joseph Clark Sent: Thursday, 23 February 2012 10:47 AM To: ozMOSS Subject: Re: At your Disposal The using block only automatically disposes variables that are declared within the initial parentheses (in this case the oSiteCollection object). The oWebsite object is constructed within the main body of the using block, so it won't get automatically cleaned up. Arguably, the demo code isn't well written, since the oWebsite variable should be declared with a using statement as well, to avoid this kind of confusion. For the record, calling dispose multiple times on the same object is safe (provided the developer wrote the dispose method correctly, which you can probably assume is true for all objects in the SharePoint API) On Thu, Feb 23, 2012 at 10:26 AM, Paul Noone <paul.no...@ceosyd.catholic.edu.au> wrote: Hi all, I continue to be confused by the continually conflicting example code I find regarding site/web disposal. Its been my understanding that using is self-disposing. But the example below includes a dispose call within the using statement. Is this correct? http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfolder.welcom epage.aspx using (SPSite oSiteCollection = new SPSite("http://MyServer/sites/MyWikiSite")) { SPWeb oWebsite = oSiteCollection.OpenWeb(); SPFolder oFolder = oWebsite.RootFolder; oFolder.WelcomePage = "My Wiki Library/MyWelcome.aspx"; oFolder.Update(); oWebsite.Dispose(); } Description: NoteNote Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Disposing Objects <http://msdn.microsoft.com/en-us/library/ee557362.aspx> . Kind regards, Paul Noone --------------------------------------------------- Online Developer/SharePoint Administrator Infrastructure Team, ICT Catholic Education Office, Sydney p: (02) 9568 8461 f: (02) 9568 8483 e: <mailto:paul.no...@ceosyd.catholic.edu.au> paul.no...@ceosyd.catholic.edu.au w: <http://www.ceosyd.catholic.edu.au/> http://www.ceosyd.catholic.edu.au/ _______________________________________________ ozmoss mailing list ozmoss@ozmoss.com http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss
<<image001.gif>>
_______________________________________________ ozmoss mailing list ozmoss@ozmoss.com http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss