2012-11-27 151 views
0

MSDN entryPrincipalSearcher.FindByIdentitiy(),加里考德威爾指出(在社區內容底部),其從使用該方法的內存泄漏的結果,因爲「底層實行使用DirectorySearcherSearchResultsCollection但不如文件所述,致電SearchResultsCollection。「當使用PrincipalSearcher.FindAll()PrincipalSearcher.FindOne()作爲解決方法時,此泄漏也顯然導致需要調用明確的Dispose()PrincipalSearcher.FindByIdentitiy()內存泄露

此條目是爲.NET 3.5製作的,但未提及.NET 4.0及更高版本中列出的問題。任何人都可以確認這個問題是否已經修復?

回答

0

就讓我們來看看與反射表明它已經固定: 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(); 
    } 
}