mercredi 18 mars 2015

Possibility of memory leaks in this code block



I have a tool using a similar code block as follows.



private void createDiscussions()
{
SPWeb newCommunitySite = null;

try
{

using (SPSite site = new SPSite(siteURL))
{
.
.
.
newCommunitySite = site.OpenWeb();
.
.
.
}
newCommunitySite.Dispose();
}
catch()
{
.
.
.
}
finally
{
newCommunitySite.Dispose();
}
}


Can this code cause memory leaks ?


Although the code looks nicely wrapped in the Using and try-catch blocks, I have the doubt because the SPWeb object was declared outside of Using and try-catch blocks. Will that be disposed properly(without causing leaks) in all scenarios ?








0 commentaires:

Enregistrer un commentaire