java - Activity中的成员变量被赋值之后,Activity被回收的时候内存才会被释放吗
大家讲道理
大家讲道理 2017-04-18 10:49:07
0
2
598

Activity中的成员变量被赋值之后,Actiity被回收的时候内存才会被释放吗
java中一个类中的成员变量被赋值之后,这个类对象被回收时,类中得成员变量才会被释放内存吗

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(2)
大家讲道理

This question should be classified under Java. As long as it is Activity所属的对象被static持有了, 那就导致整个Activity一直存在在内存中. 除非使用WearReference.

The following is a similar error code demonstration:

private static Context sContext;
public static void setContext(Context context) {
    sContext = context;
}

If you use Android Studio, the IDE will have a warning: Do not assign the Context object to static variables.

伊谢尔伦

The description of the question is unclear, and there are no negative comments on the punctuation. But try to answer:
Global objects should only be variables modified by the static modifier. Variables after static modification belong to this class (class), or change the class corresponding to All objects, not belonging to a certain object. From this derivation, you should be able to realize that it is wrong for an object to be recycled to cause static to be recycled (how to use other objects after it is recycled)
Here we talk about Activity, let’s expand on it. Under normal circumstances, it is okay to use static variables to reference the current object (such as singleton mode), but in the design of Android, Activity is not an ordinary class. It has its own life cycle and will be recycled when it expires (because the function is too powerful , occupying too much memory). So there is a problem of using static reference to the current Activity to report a memory leak.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!