Вопрос

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);

            try
            {
                Method1(destinationItem, destinationWP, sourceWP);
                Method2(sourceItem, destinationItem);
            }
            catch (Exception err)
            {
                SPContextManager.Current.LogManager.LogErrorToDevelopers(err);
            }
            finally
            {
                destinationWP.Dispose();
                sourceWP.Dispose();
            }

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с sharepoint.stackexchange
scroll top