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.
This question should be classified under Java. As long as it is
Activity
所属的对象被static持有了, 那就导致整个Activity
一直存在在内存中. 除非使用WearReference
.The following is a similar error code demonstration:
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.