The reasons for the memory leak problem caused by Android performance optimization

1) Singleton mode results: Because a single column is static, it is consistent with the life cycle of the program. If an object is no longer needed, and the singleton that the object originally referenced still holds use of the object, then the object cannot be recycled. For example, the context of the Activity is passed to the singleton.



2) Caused by inner class (solution: change to static inner class);


3) Handler inner class;


4) Try to avoid using static member variables;


5) Caused by the resource not being closed;


6) Problems with SharedPreferences

                       1) Cross-process synchronization cannot be achieved;
                       2) The data of the size of the file cannot be stored
                          [When the data in the sp is too large and the data is obtained from the sp, the main thread may be blocked, causing the ui to freeze]
                          [Parsing a large sp When , a lot of temporary objects will be generated, resulting in frequent GC recycling, and a large number of GC will cause memory jitter]


7)............

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325509804&siteId=291194637
Recommended