System.DirectoryService / dispose()

G

Guest

Hi
Just wonder if we need to call dispose() explicitly in our code for things
other than DirectoryEntry, such as DirectorySearcher ...?

TIA

--
 
J

Joe Kaplan \(MVP - ADSI\)

Yes, definitely. This pretty much goes for anything that implements
IDisposable as a general recommendation, but is even more important with the
DirectoryEntry specifically because the Dispose method is the only thing
that releases underlying COM object. This is a bug that exists in .NET 1.1
that is fixed in 2.0.

While we are talking about it, the FindOne method will also "leak" a
SearchResultCollection object if FindOne doesn't find anything (returns
nothing). For this reason, it is safer to always use FindAll so you can
explicitly call Dispose on the SearchResultCollection.

Joe K.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top