Http://www.jianshu.com/p/216b03c22bb8Memory 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.Familiar with Android
the shortest time for each GC operation, old generation second, and permanent generation longest. The length of the execution time is also related to the number of objects in the current generation, and it is much slower to traverse the tree structure to find 20,000 objects than to traverse 50 objects.
(2) Memory test plugin
1) leakcanary Introduction
Leakcanary is a tool for detecting memory leaks that
Android is an effective solution to the problem of memory leaks
Android memory leak, I want to do the Android application when I encountered a headache, here is a good information I find on the Internet, examples of the solution to this problem
Foreword: Recently in studying handler knowledge, which involves a problem, how to avoid the memory overflow problem caused by handler. Find a lot of information on the Internet, there are a lot of copying each other, there is no practical role.
The me
How can Android effectively solve the problem of Memory leakage and android leakage?
Recently, I have been studying Handler's knowledge about how to avoid memory overflow caused by Handler. I found a lot of information on the Internet, many of which are copied from each other and have no practical effect.
The memory leak detection tool in this article is: LeakCanary github address: https://github.com/square/leakca
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 "+".Avoid memory leaks for
Google Play notes: For developers, everyone wants their apps to get more exposure on Google Play, so Google has recently offered 10 ways to improve the app's exposure on Google Play, for example. and 10 kinds of taboo behaviors that Google Play doesn't like.
Tutorial
"Leakcanary: Let the memory leak no hiding": Recently square Open source A memory leak automatic detection artifact--leakcanary, it
classes based on api interfaces. This plug-in automates this process and is ready for use.
4. Android Parcelable Code Generator
There are two serialization methods in Android: Serializable interface and Parcelable interface. However, Parcelable is recommended in Android, but this method is more complicated than Serializable, with this plug-in, everything will be OK.
5. LeakCanary
It is strongly recommended to help you easily detect memory leaks d
interface, which automates the process and uses it quickly.4. Android parcelable Code GeneratorThere 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, Leakcanary--Non-plug-inIt is highly recommended to help you detect memory leaks co
, Fresco is a powerful picture loading component that supports the loading of Gif and WebP formats, supports Android2.3 (API level 9) and above, and Fresco designed I Mage Pipeline and Drawees two modules each, so that the picture is loaded 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 cod
of objects in memory, and views which objects cannot be reclaimed by the garbage collector. You can visually view the objects that may be causing the result through the view.
Leakcanary Tools:
Simple, fool-type operation. This tool is open source on GitHub, is produced by the Square company, not a word, square produced must be a boutique, https://github.com/square/leakcanary we can quote it i
references to those objects. For example, now to see the references contained in leakactivity, you can click the right mouse button to select the With incoming reference in the list objects. The With Outcoming reference indicates that the selected object holds references to those objects.Here to write a picture description
Dominator Tree
Now click here to click the Dominator Tree button and search for activity. You can see the following illustration:
Here you can see that there are a lot
+ LeakCanary.Page Layout: select the usage mode for the Spinner, And the ProgressBar displays the update status. You can choose to start LeakCanary.
Main logic:(1) Use Fragment to store page information, including asynchronous tasks, RxJava observers and topics.
// Set the storage Fragment FragmentManager fm = getFragmentManager (); mRetainedFragment = (RetainedFragment) fm. findFragmentByTag (RETAINED_FRAGMENT); if (mRetainedFragment = null) {mRetai
link One:http://stormzhang.com/android/2015/05/26/android-tools/
Butterknife Zelezny
Selectorchapek
Designers to provide us with all kinds of resources, each button to write a selector is not very troublesome? So this plug-in to solve this problem, you only need to do is to tell the designers to follow the code named just fine, the other one button to fix.
Gsonformat
Most server-side APIs are now returned in JSON data format, and the client needs to generate the c
-universal-image-loader the use of the asynchronous Load Class library (Hyper-verbose configuration)Android Open Source Framework Universal-image-loader full ParseAndroid Universal Image Loader Source Analysis
8. Memory Leak detection function library LeakcanaryLeakcanary is another masterpiece of square, which can be used to monitor memory leaks in the debug version of Activity,fragment, and after using this library, square fixes a lot of memory leaks and even discovers leaks in the Androi
much to describe the theory of things, Daniel's articles have been written, I will no longer describe. So how do we solve the problem of memory leaks? For the small white we certainly want to have an easy-to-use, quick-positioning memory leak plug-in, then I recommend leakcanary fool-type detection tool for everyone.OK, the first step must be how to quote this in the project? First, the way that Android Studio projects reference third-party libraries
ObjectiveFor memory leaks, I think we have all experienced in development, except that memory leaks are not visible to us because they are active in the heap, and to detect memory leaks in programs, we can often use tools like Leakcanary, mat, and so on to detect memory leaks in applications. , Mat is a powerful memory analysis tool that is versatile and complex, while Leakcanary is a lightweight third-part
' com.jakewharton.hugo:hugo-plugin:1.2.1 '}}Print plug-in for easy debugging of performance issues. By adding @debuglog to the method, you can output the invocation parameters and the execution time.Apply plugin: ' Com.jakewharton.hugo ' java: @DebugLogpublic void Test (int a) {int b=a*a;}Iv. Memory performance Analysis and optimization1. Memory leaksThis problem is generally used in the project Leakcanary basic can be done, configuration is quite si
Tutorial
Leakcanary: Let the memory leak no hiding Some objects have a limited life cycle. When these objects are done, we expect them to be recycled. But if there is a series of references to this object, it will not be recycled when we expect it to be retracted at the end of the object's life cycle. It also consumes memory, which creates a memory leak. Continuous accumulation, memory is quickly exhausted.
Mobile-size Basics (@
recommendations are not necessarily modified, you can let the programmer according to their own needs to modify9.LeakCanaryWe can either use the memory leak detection tool in Android Studio, or use the instrumentation tool in the app, and the following is a recommended tool for leakcanary in the memory provided by the Square company. It makes it easy to give users hints when a memory leak occurs in the application. Its github address, let's see how i
necessary to hold some references
It is also important to note that when using non-static inner classes, they hold references to external classes. (use RxJava's classmate in subscribe also should notice unsubscribe)
Note Releasing resources at the end of the life cycle
When using property animations, stop (especially looping animations) when not in use, otherwise a memory leak will occur (Activity cannot be released) (View animation will not)
Introduction to several memory dete
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.