静态成员垃圾收集 [英] Garbage collection of static members

查看:150
本文介绍了静态成员垃圾收集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将静态成员是有史以来所收集的垃圾收集器?

Will static members be ever collected by the garbage collector?

推荐答案

通过静态变量引用的对象将只被垃圾收集时,相关的的AppDomain 是垃圾收集。在客户端应用程序,但往往只是一个单一的的AppDomain 这住了过程的持续时间。当应用程序使用一个插件架构(一个例外是 - 不同的插件可以在不同的的AppDomain 和加载的的AppDomain 以后可以卸载。)

Objects referenced by static variables will only be garbage collected when the relevant AppDomain is garbage collected. In client applications, there's often just a single AppDomain which lives for the duration of the process. (An exception is when the application uses a plug-in architecture - different plug-ins may be loaded in different AppDomains and the AppDomain may be unloaded later.)

在ASP.NET中,的AppDomain 再利用定期发生(因各种原因) - 当这种情况发生,那的AppDomain中的静态变量将不再担任GC根,因而不会prevent对象被垃圾收集。

In ASP.NET, "AppDomain recycling" happens periodically (for various reasons) - when this occurs, and the static variables within that AppDomain will no longer act as GC roots, and thus won't prevent objects being garbage collected.

如果你担心收集的,而你仍然有对它的引用通过一个静态变量中的对象是垃圾,不过,你可以放松。虽然你可以访问对象,它不会被垃圾回收。

If you were worried about an object being garbage collected while you still had a reference to it via a static variable, though, you can relax. While you can access the object, it won't be garbage collected.

这篇关于静态成员垃圾收集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆