is it possible for Android VM to garbage collect static variables without killing the whole Android application?

前端 未结 2 1397
难免孤独
难免孤独 2020-12-15 23:46

(Title is misleading since garbage collectors collect only objects, but I found this title more straightforward)

Suppose I have an Android application with

2条回答
  •  北荒
    北荒 (楼主)
    2020-12-16 00:07

    If you are making the variable static so that you can access it from anywhere in your app without creating a new instance of the class every time I believe this is a good candidate for the Singleton pattern.

    String userid = Global.getInstance().userid;
    

提交回复
热议问题