I’m currently writing a piece of code that does some searches which returns IDisposable objects (DirectoryEntry to be specific from an ADAM instance) and I end up with code similar to
using(var entry = (from result in results
let entry = result.GetDirectoryEntry()
where entry != null
select entry).Last())
{
//blah blah
}
but who is then responsible for Disposing the objects not returned by the above query? or more to the point is the above code actually missing a call to Dispose() for all other entries than the last?
if it is Linq to Objects then you are responsible. Yes, objects will not be disposed. You should take the results of query before
LastandDisposethem manually.