Let's suppose I have this function that can be called several times from the main thread. Every time this is called, I create a WebClient
object to download some data asynchronously.
My question... is this safe to do? Is the WebClient
object released after the event is called? I wouldn't like to keep allocating memory if it is not going to be freed automatically.
My application is for WP7 with Silverlight.
Thanks!
void DownloadData(string cURL)
{
WebClient webClient = new WebClient();
webClient.DownloadStringCompleted +=
new System.Net.DownloadStringCompletedEventHandler(
webClient_DownloadStringCompleted);
webClient.DownloadStringAsync(new Uri(cURL));
}
static void webClient_DownloadStringCompleted(object sender,
System.Net.DownloadStringCompletedEventArgs e)
{
...
}