"Android Development Art Exploration" reading notes (14)--jni and NDK programming
NO1:
If <include> developed this id attribute, and the root element of the included layout file also has an id attribute, the <include> specified id attribute is
No2:
Drawing optimization
1) do not create a new local object in OnDraw
2) do not take time-consuming tasks in the OnDraw method
No3:
Memory leak optimization
Scenario One: Memory leaks due to static variables:
If a static variable holds an activity, the activity cannot be released in time.
WORKAROUND: 1 Use the application context. 2 Caution with statistic keywords
Scenario Two: A memory leak caused by a singleton mode:
Because the life cycle of the singleton pattern is consistent with the application, if the singleton mode holds a activtiy, the activity cannot be released in time
Workaround: Use application's global context as much as possible.
Scenario Three: Memory leaks caused by property animations:
Because the activity view is animated, and view has activity, if the animation is infinite , the activity will not be released in time.
Workaround: Call animator.cancel() in the activity's ondestory to stop the animation
No4:
After a process has been ANR, the system creates a file traces.txtin the /data/anr directory.
NO5:
Recommendations for performance optimization
1) Avoid creating too many objects
2) do not use enumerations too much, the enumeration takes up more memory space than the shaping
3) constants, use static final to decorate
4) use some Android-specific data structures, such as Sparsearray and pair, for better performance
5) Appropriate use of soft and weak references
6) Use memory cache and disk cache
7) Use static internal classes as much as possible to avoid potential memory leaks due to internal classes
"Android Development Art Quest" Reading notes (15)--android performance optimization