Disposing of StatsdUDP
AnthonySteele opened this issue · 3 comments
StatsdUDP is IDisposable and apparently not disposing of it can cause leaks. This is because it wraps a UdpClient. Classes that wrap a disposable object often themselves become disposable in this way.
Should we document the requirement to dispose the UdpClient?
Alternatively, the StatsdUDP is used in the Statsd class, e.g.
Statsd s = new Statsd(new StatsdUDP(HOSTNAME, PORT));
If a StatsdUDP is never re-used across different Statsd, should Statsd become IDisposable too?
Yes, Statsd should become IDisposable because it holds a StatsUDP instance (as a field) which is IDisposable.
Also, IStatsUDP may need to inherit from IDisposable too.
Last but not least, this is actually a memory leak: Metrics.Configure() method creates a StatsUDP instance, which is never disposed.
Metrics.Configure() method creates a (single) StatsUDP instance, which is never disposed. While this is technically a memory leak, it's hard to tell when to dispose of it - as long as the app is running, you can call e.g. Metrics.Counter("foo")
and make use of it.
I have submitted an update to the docs that shows the current behaviour
#12
Before any changes to the code.