Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR add
IDisposable
to some of our moving parts that (may) need it.Historically we did not do this because this parts are expected to live for the duration of your application but it does not hurt to be explicit.
SniffingConnectionPools
holds a ref to ReaderWriterLock which needs to dispose some events.Transport
held a SemaphoreSlim which really holds a system handle.The ownership of the semaphore (used for sniffing on startup) moves to
ConnectionSettings
with this PR becausenew ElasticClient()
implicitly creates a newTransport()
each time, eventhough theIConnectionPool
interface is already resilient to this it means we create more Semaphores then strictly needed if folks are new'ing clients all the time.Therefore this PR also introduces some documentation on the recommended life times of our objects.
See this test for more info
The interfaces implement IDisposable for it's Level1 disposables using the pattern as outlined by Stephen Cleary:
http://www.codeproject.com/Articles/29534/IDisposable-What-Your-Mother-Never-Told-You-About
No object disposed exceptions are thrown as the previous article explains:
To help prevent getting into this state all the Dispose() methods are explicitly implemented.
More rants against the classical dispose pattern: http://blogs.msmvps.com/peterritchie/2013/01/20/the-dispose-pattern-as-an-anti-pattern/