I have used SPDisposeCheck command line utility on following code and it gives comments as

"Dispose Explicitly Called on SPLimitedWebPartManager.Web".

I carefully analyse my code for any potential memory leaks but I don't find any issue and I properly called Dispose method. This is the code which I think handled properly for any memory leak:

private static void MyWebParts(SPListItem sourceItem, SPListItem destinationItem, bool somevariable)

            SPLimitedWebPartManager sourceWP = sourceItem.File.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
            SPLimitedWebPartManager destinationWP = destinationItem.File.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);

                Method1(destinationItem, destinationWP, sourceWP);
                Method2(sourceItem, destinationItem);
            catch (Exception err)

I have dispose the SPLimitedWebPartManager Objects and it seems there is no memory leaks, but SPDIsposeCheck command line tool gives this comments:

  1. Dispose Explicitly Called on SPLimitedWebPartManager.Web sourceWP.{Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager}Dispose()

  2. Dispose Explicitly Called on SPLimitedWebPartManager.Web destinationWP.{Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager}Dispose()

Why is that ??


Indeed, I'm quite sure your code is good; this is most probably a false positive from SPDisposeCheck.
As Stefan Goßner states here false positives can definitely happen. And another one here.
And here Anita explains how to suppress these false positives if the bother you.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.