I have a WinForm application that periodically polls a TCP server and downloads some user data (JSON notation). For some reason, the memory usage of this application increases with every call of the method below:
private void timerElapsed(object sender, ElapsedEventArgs e)
{
if (!isPolling)
{
isPolling = true;
try
{
using (System.Net.WebClient wc = new System.Net.WebClient())
{
jsonTemp = wc.DownloadString(serverUrl);
isPolling = false;
}
}
catch (Exception ex)
{
isPolling = false;
}
}
else
{
isPolling = false;
}
}
Whenever wc.DownloadString is being called, the footprint of my application increases.
Since WebClient already implements IDisposable, it should automatically be disposed after the using directive, or am I wrong?