2
Vote

Memory Leak in DirectoryQuery.GetResults()

description

The following line causes a memory leak:
"foreach (SearchResult sr in s.FindAll())"
 
The reason for this can be found here:
http://msdn.microsoft.com/en-us/library/system.directoryservices.directorysearcher.findall.aspx
 
Ultimately, any time you use a SearchResultCollection object (such as when you call DirectorySearcher.FindAll), you must dispose the SearchResultCollection object yourself. A fix would be to put the s.FindAll() result into a variable managed by a USING block.

comments

jaxidian wrote Mar 18, 2010 at 8:13 PM

Had wrong class name.

bdesmet wrote Jul 16, 2010 at 8:06 AM

Will be addressed in an upcoming release.

wrote Jun 4, 2011 at 2:32 PM

wrote Feb 14, 2013 at 7:56 PM