问题描述
假设我有一类,它没有任何直接/间接引用问题的对象(如背景,观点,...)的一个实例的引用。是否有使用的静态引用此引用,并使用它,它扩展了应用程序里面的类之间的差异
类?
Suppose I have a reference to an instance of a class, which doesn't have any direct/indirect reference to problematic objects (like context,views,...). Are there any differences between using this reference in a static reference and using it inside the class that extends the Application
class?
我的意思是,这两种方式引用的对象将只在进程被杀死(或当有未被引用),右中解脱出来?也许有使用多个进程时,是有区别的?
I mean, in both ways the referenced object will be freed only when the process is killed (or when there are no references to it), right? Maybe there is a difference when using multiple processes?
推荐答案
我相信文章由@Angelo对方的回答引用是非常错误的(至少可以这样说),并引起了很大的困惑:在Android类是基于每个进程的基础卸载不是在每个阶级基础。也就是说,如果您的应用程序被杀害的和的类被卸载你失去的所有的静止状态 - 如果不是没有。这就是我做@法登的答案,至少有:
I believe the article cited in the other answer by @Angelo is very wrong (to say the least) and caused much confusion : the classes in android are unloaded on a per process basis not on a per class basis. That is if your app is killed and the classes are unloaded you lose all static state - if not no. That is what I make of @fadden's answers at least :
Is它仍然是Android的卸载从未班?的情况下
Android:什么时候类得到由系统中卸载?
现在你的问题是有点含糊......无论它的使用静态引用是不一样的非静态的。如果你的意思是两个变量是静态的话就没有区别,如果他们是在一个活动,应用程序或任何实例 - 每当类被加载,并且变量采取一定的价值,他们将继续这样做,直到类卸载。不知道如果有卸货的类指定的顺序 - 如果将重要
Now your question is a bit vague... A static reference is not the same as a non static wherever it's used. If you mean that both variables are static then there is no difference if they are in an activity, application or whatever instance - whenever the class is loaded and the variables take some value they will remain so till the classes are unloaded. Not sure if there is a specified order in unloading the classes - or if that would matter.
这篇关于应用类中的静态参考和借鉴之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!