LEM*_*LEM 7 c# silverlight asynchronous webclient windows-phone-7
假设我有这个函数,可以从主线程中多次调用.每次调用它时,我都会创建一个WebClient对象来异步下载一些数据.
我的问题......这样做安全吗?WebClient事件被调用后是否释放了对象?如果它不会自动释放,我不想继续分配内存.
我的应用程序适用于带Silverlight的WP7.
谢谢!
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)
{
...
}
Run Code Online (Sandbox Code Playgroud)
Bue*_*ler -4
WebClient 不实现 iDisposable 接口,因此无需执行任何特殊操作即可进行正确的垃圾收集。当CLR检测到当前没有对该对象的引用时,它将被安排进行垃圾回收。当然,您不知道这种情况何时会发生,因此内存可能会也可能不会(很可能不会)立即释放。
| 归档时间: |
|
| 查看次数: |
8396 次 |
| 最近记录: |