0

下面的代码是否泄漏内存?如果是这样,有什么优化它的建议吗?

SPWeb web = (SPWeb)properties.Feature.Parent; // comes from the event receiver
//... lots of other code

// the below is the focal point.
foreach (SPWeb childWeb in web.Webs) 
{
    try
    {
        // lots of heavy processing with the childWebs
    }
    finally
    {
        if (childWeb != null)
        {
            childWeb.Dispose();
        }
    }
}
4

2 回答 2

3

您发布的代码应该没问题。但是,根据您在 try 语句中对 childWeb 所做的操作,它可能会导致内存泄漏。你可以发布整个代码吗?你怀疑内存泄漏吗?

于 2012-04-26T06:54:21.263 回答
1

According to Disposing Objects, your code matches the Good Coding Practice for SPWeb.Webs.

As mentioned on that page, I would recommend downloading and using SPDisposeCheck as both verification of correct code and identification of potential memory leaks.

于 2012-04-26T12:37:47.733 回答