requestsUse MVP mode to standardize behavior of large activity classes to avoid memory leaks caused by asynchronous tasksAvoid memory leaksUnderstanding the virtual machine Memory recovery mechanismFrequent GC can also cause cotton to avoid unnecessary memory overheadIncorrect reference to the ♂ potential caused by the memory leak (ah ~ to vent ~)Common activity leaks (single case, application, background thread, infinite animation, static reference)Bitmap leaks (honeycomb the problem before th
to implement the Serializable interface and the Parcelable interface, but it is recommended to use parcelable in Android, but this is more cumbersome than the serializable approach. Then with this plugin everything is OK.5, LeakcanaryIt is highly recommended to help you detect memory leaks conveniently during the development phase, which is easier and easier to use.English is not good here have Comrade Lei Feng translation of Chinese version leakcanary
client needs to generate the corresponding entity classes based on the API interface, which automates the process and uses it quickly.4, ParcelablegeneratorThere are two ways to serialize in Android, which is to implement the Serializable interface and the Parcelable interface, but it is recommended to use parcelable in Android, but this is more cumbersome than the serializable approach. Then with this plugin everything is OK.5, LeakcanaryConscience Business Square recently open source of a ver
the problem as far as possible all recall?
A new approach to problem location on moving tip:Based on the plug-in system, do a test plug-in, all of us feel useful in the offline testing ability to enter, while integrating the industry well-known good framework, such as dexposed, leakcanary, and some systems open but the main version of the use will affect the performance of good things traceviewer, Choreographer, Activitylifecyclecallback and so
queen, and then we can detect if the Queen is null to see if the object has not been cleaned, the null description has not been cleaned, Non-null description is cleared, memory detection public leakcanary Use this principle to do, in more than one mouth, memory detection public and MAT,DDMS heap can be detected4: Virtual reference, not a true reference type, is used to detect memory leaks1: The first solution to handler static so there is no internal
only need to perform large memory operations (such as loading a photo wall) during this period ), there is a risk that OOM is caused by this memory leak (the memory is definitely less occupied)
How can I modify the above?
Change Runnable and Handler to static or use them within the external definition.Other common memory leaks
Static variable Memory leakage: When a static variable is used to reference a thing, the reference will always leak if it is not used.
Memory leakage caused by singlet
Unit Test framework
Android comes with a lot of test tools: Junit,monkeyrunner,uiautomator,espresso, etc.13. Debugging the Framework
name
Description
Stetho
Debug your Android app's bridge, making it possible to debug with chrome developer tools
14. Performance optimization
name
Description
Leakcanary
Memory Leak Detec
is being emptied from the background process;
Application of inexplicable crashes (i.e. exceeding the heepsize threshold caused by oom);
Memory Leak analysis ToolSeeing these problems, I suddenly found that it was almost 0.0 closer to the truth.To get a clearer picture of the current application's memory usage in real time, we need some tools to implement it. There are two types of tools that are more useful:
Memory Analyzer Tool
Leakc
Rxjavajoins
Provides joins operation for Rxjava
Rxandroid
Responsive extensions on Android, added Android thread scheduling on Rxjava basis
Rxbinding
Provides an API to bind the Android UI with Rxjava
Agera
Responsive programming on Android
A. Log framework
name
Description
Logger
Simple, beautiful, powerful Android logging tool
Hugo
Log
Collect information once per GC
Find a memory leak weapon
Disadvantages
Use complex
Displays the allocated object size information (package view)
2.4 Leak Canary
Https://github.com/square/leakcanary
Reference dependencies { ‘com.squareup.leakcanary:leakcanary-android:1.3‘ releaseCompile ‘com.squareup.leakcanary:leakcanary-android-no-op:1.3‘ }
Use Memory Leak DetectionPr
1, mainly introduced a number of analytical tools, such as GT, ITest, etc.Http://www.jianshu.com/p/8b77d394b2a62. Detailed description of the Android Platform Common Performance optimization toolhttp://blog.csdn.net/yanbober/article/details/48394201For example:UI aspect: The GPU Overdraw tool provided by Android system, GPU rendering mode analysis and so on. Lint fast analysis unreasonable understanding of UI layout, Hierarchyviewer detailed analysis of the view layout.adb shell Dumpsys me
few buffers, when not in use, should close them in time.
The registration object is not logged off. For example, an event that does not log off after registration causes the object's reference to be maintained in the Observer list.
The static variables of the class hold large data objects.
A static instance of a non-static inner class.
Handler temporary memory leaks. If the handler is non-static, it is easy to cause Activity or Service not to be recycled.
A memory leak cause
reasonably; use LRUCache cacheC. Use static inner class +weakreference instead of inner classes, such as handler, threads, AsynctaskD. Use thread pooling to manage threads and avoid new threadsE. Use a singleton to hold the context, need to remember to release, or use the global contextF. Static collection objects note releaseG. Property animations cause memory leaksH. Use of WebView, activity.ondestory need to be removed and destroyed, Webview.removeallviews () and Webview.destory ()Standby: U
Okhttp IntroductionOkhttp is a third-party class library for requesting networks in Android. This is an open source project and is Android's hottest lightweight framework, contributed by the mobile payment Square company (the company also contributed Picasso and Leakcanary). Used in place of HttpURLConnection and Apache HttpClient (HttpClient removed from Android API23).Okhttp has its own official website, website: okhttp official website If you want
. Androidanotations Fast Android development. Easy to maintain roboguiceandroid platform Google Guice
8. Chart
Williamchart Create a chart of the Android library Hellocharts compatible to API8 's Android Chart Gallery mpandroidchart a powerful Android chart view/graphics library
9. Background processing
Tape a brisk, transactional, file-based FIFO library Android Priority job queue for Android easy to schedule task
10. Event Bus
Eventbus an optimized event bus that simplifies communication
the activity is terminated.
Four. Prevent oom
1. Bitmap: Lazy load, LRU cache, Bitmap compression (according to ImageView size), block loading large image.
2. Large files, such as TXT, and so on, segmented loading.
3. Listviewgridview to do multiplexing optimization. Using Viewholder,settag
Five. View optimization
1. Optimize layout level, layout reuse, use Include,merge label.
2. Avoid excessive drawing, reduce elements, layout overlap, open debuggpu overdraw debugging, use Hierarchy Vi
, Google has few success stories and recommends only a few 12. Log Frame Name Description Logger Simple, pretty, powerful Android log tool Hugo on debug version notes the triggering method for logging Timber a small, extensible log tool 13. Test Framework Name Description Mockito Java-written mocking unit test framework robotium Android UI Test robolectric Android Unit Test framework
Android takes a lot of test tools: Junit,monkeyrunner,uiautomator,espresso 14. The debug framework name describe
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.