0

MSDN 条目PrincipalSearcher.FindByIdentitiy(),Gary Caldwell 指出(在社区内容的底部)使用此方法会导致内存泄漏,因为“底层实现使用DirectorySearcherSearchResultsCollection不调用 dispose,SearchResultsCollection如文档所述。” Dispose()此泄漏显然还导致在使用PrincipalSearcher.FindAll()PrincipalSearcher.FindOne()作为解决方法时需要调用显式。

此条目是针对 .NET 3.5 制作的,但未列出针对 .NET 4.0 及更高版本的问题。谁能确认此问题是否已解决?

4

1 回答 1

0

快速浏览一下 Reflector 表明它已被修复 System.DirectoryServices.AccountManagement.ADStoreCtx FindPrincipalByIdentRefHelper

DirectorySearcher searcher = new DirectorySearcher(this.ctxBase);
SearchResultCollection results = null;
try
{
   ...
}
catch (COMException exception)
{
    throw ExceptionHelper.GetExceptionFromCOMException(exception);
}
finally
{
    searcher.Dispose();
    if (results != null)
    {
        results.Dispose();
    }
}
于 2012-11-27T21:16:14.047 回答