the mobile SDk must be converted before it can be recognized by MAT. The Android SDK provides the hprof-conv tool (under sdk/tools)First, go to your android sdk tools directory on the console and run the following command:./Hprof-conv xxx-a.hprof xxx-b.hprofFor example, hprof-conv input. hprof out. hprofIn this case, the out. hprof can be opened in the MAT of eclipse.The following describes LeakCanary, a dashboard tool.LeakCanary
What is
convenience of debugging performance problems. Add @ DebugLog to the access method to output the call parameters and execution time of the method;
Apply plugin: 'com. jakewharton. hugo'
Java:
@ DebugLog
Public void test (int ){
Int B = a *;
}
Iv. Memory Performance Analysis and Optimization
1. Memory leakage
Currently, leakcanary can be basically used in projects, and the configuration is quite simple:
Build. gradle:
Dependencies {
DebugCompile 'com.
() {Super. OnDestroy ();//Use leakcanary to see if there is a memory leakMyapplication.getrefwatcher (). Watch ( This); }}Leakcanary detected memory leaks:why not? In the above code, we declare a static activity variable and refer to the currently running activity instance in the TextView onclick event, so if the reference is not cleared before the end of the activity's life cycle, it will cause a memory le
Use the new Android Studio version to detect memory leakage and Performance
Memory leakage is the biggest headache for Android Developers. A small memory leak may all be an ant hole broken down by the treasure of thousands of miles.How can we detect memory leaks? There are a lot of online tutorials, but many of them are detected using Eclipse. In fact, Android Studio after version 1.3 is very convenient to detect memory. If you use the MAT tool and LeakCanar
artifact. This is the project's GitHub warehouse address: Https://github.com/square/leakcanary. It is very easy to use a package dependency in Build.gradle:Debugcompile ' com.squareup.leakcanary:leakcanary-android:1.5 ' releasecompile ' com.squareup.leakcanary: leakcanary-android-no-op:1.5 ' testcompile ' com.squareup.leakcanary:leakcanary-android-no-op:1.5 ' Add initialization code in OnCreate method in a
run.Memory leak concept and its impactmemory leaks in layman's words, an object that is supposed to be recycled is not recycled for some reason. we all know that the object is life cycle, from birth to death, when the object's task is completed, the Android system for garbage collection. We know that the Android system allocates a limited amount of memory for an app (which may vary depending on the model), and when a memory leak occurs in an application, it inevitably causes the application to
memory leaks are the biggest headache for Android developers.Perhaps a small memory leak, could be destroyed in the dikes nest.
How can I detect a memory leak? There are many online tutorials, but many are using eclipse detection, in fact, after the 1.3 version of Android Studio detection memory is very convenient, if combined with the Mat tool, Leakcanary plug-ins, everything becomes so easy.Familiarity with the Android studio int
AndroidStudio to save trouble)
5. In the opened hprof file, we can easily find the package name of our application and open the corresponding package to see the memory usage.
Use LeakCanary to analyze application memory usage
LeakCanary is an open-source java library that detects memory leaks in the debug version.GitHub address: https://github.com/square/leakcanary
Gumshoe is a Java program Detection tool that can help you track the load and performance of your program. It can help you to analyze the usage of resources by measuring TCP,UDP,CPU usage information, and it also provides the analysis function of the call stack in Java program, such as the number of times, frequency and other information of a method call. leakcanary-memory leaks monitoring memory leaks has always been a problem for Java programmers,
This chapter deals with the performance optimization and processing of real-world case studies in Android development. Design to knowledge points have weak references, Memory Monitor,allocation tracker and Leakcanary plugins.1. Test DemoDownload bug item: https://github.com/lzyzsd/MemoryBugs, please use Memorymonitor, Allocationtracker and Heapdump, Leakcanary and other tools to find potential memory proble
context can not be released, Causes the corresponding component to be unable to be reclaimed by memory when exiting. 3. The non-static inner class holds a reference to the external class by default, so that if we define a thread inner class in activity and run the thread directly from the new thread, the thread will hold a reference to the activity before the end of the run. This causes the activity to not be released.Memory Detection ToolsLeakcananryLeakcanary, the main monitoring is the use o
The object itself occupies memory size
Retained Size
The amount of memory saved after releasing the object
Dominating Size
The size of the memory that governs
3, Leakcanary
How to useAdd references in Build.gradle, different compilations use different references:
{ debugCompile ‘com.squareup.leakcanary:leakcanary-android:1.3‘ releaseCompile ‘com.squareup.leakcanary:leakcanary-a
perfectly, want to know more image pipeline and drawees about its features, can go to its official platform to see the introduction
Zxing.
ZXing is the most famous open source project in the field of QR Code, it provides two-dimensional code/Barcode scanning solution for multiple platforms, with fast scanning, high recognition rate, simple use and other features.
Leakcanary.
the introduction http://android-developers.blogspot.com/2011/03/ Memory-analysis-for-android.html, recommend a Chinese blog,http://blog.csdn.net/guolin_blog/article/details/42238633, it's very well written.The Mat tool is commonly used to analyze memory because an application has a memory leak and needs to analyze where it might leak, and then use the Mat tool to verify it. The recent open source of a memory leak detection project by Square Leakcanary
, because he will quickly increase the use of memory, and it is easy to cause frequent GC, or even memory jitter;
StringBuilder: In some cases, the code will need to use a lot of string concatenation operations, it is necessary to consider the use of StringBuilder to replace the frequent "+";
avoid creating objects within a For statement ;
...
avoid memory leaks for objectsThe leakage of memory objects can cause some objects that are no longer in use to be released in a timely m
than traversing 50 objects.(2) memory test plug-in 1) LeakCanary Introduction
LeakCanary is a tool used to detect memory leaks. It can be used for Java and Android and is contributed by Square, a famous open-source organization.
2) How LeakCanary works
RefWatcher. watch () creates a KeyedWeakReference object for North monitoring.
Next, check whether the refer
that is not released after use (the value stored by the stack's storage space), resulting in the deposit element being occupied. Until the end of the program. (In fact, the memory space is not recycled after use) is called memory leaksMemory AnalysisHow do we know if there is a memory leak that requires a memory analysis tool mat, or an open source project Leakcanary, first of all, we'll go to the official website to find out about the use of mat and
, it is recommended to adopt carefully.4) Avoid executing object creation in OnDraw methodSimilar to the frequent call method such as OnDraw, it is important to avoid doing the creation of objects here, because he will quickly increase the use of memory, but also easily caused by frequent GC, or even memory jitter.5) StringBuilderIn some cases, the code will need to use a large number of string concatenation operations, it is necessary to consider the use of StringBuilder to replace the frequent
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.