Android: Memory Optimization summary, android Memory Optimization
Memory Optimization for android is very important for large-scale android projects! Today, let's take a few common examples.
1. Reference of Context
In addition to Activity and Fragment, when using Context, try to use Application Context. In AndroidAnnotations, that is:
@RootContextContext context;
Cause: the life cycle of the application Context is long, and it can coexist with our app. We should try not to hold the Context of the Activity because it has a short life cycle. Otherwise, it may occur, after the Activity exits, its Context is still held by the EBean object.
2. Bitmap
Bitmap is a large memory occupied by android. Note the following:
2.1 If the Bitmap is not needed, call recycle () to destroy it in time.
2.2 When configuring Bitmap, you can set a certain sampling rate.
3. Cursor
When we read the ContentProvider of a third-party application or system, we usually call the add, delete, modify, and query method of getContentResolver () to obtain the Cursor object and then perform operations. After the operation is complete, remember to turn it off!
4. ListView and GridView
ListView and GridView must be used for View reuse. programmers who do not know how to use them are not qualified android programmers.
5. Custom Controls
We often use View or SurfaceView to customize our own controls. We usually use a Thread to draw them on a regular basis. The View usually uses the postInvalidate () and onDraw () methods. Note: when we Override its onDetachWindow method, remember to stop thread rendering and release resources in time, especially some image resources.
6. BroadcastReceiver must check the paired appearance of register and unregister.
7. When Handler is used, it must be declared as static
8. java containers in singleton mode, such as List, Queue, Stack, and Map, must promptly call the clear method when appropriate, because, if these containers still retain references to objects that are no longer applicable, JVM will think that the object is still referenced and will not be released. Otherwise, memory leakage may occur.
..............................
Memory analysis tools:
1. In Eclipse, open the DDMS view and select the package name of our application. We can Dump the memory usage of our application.
2. Plug-In MAT (memory analysis tool) on the third part of Eclipse)
3. adb command
Follow these steps:
A). adb shell
Adb enters mobile phone
B). ps
View all processes and package names. Note that we need to check the package name and pid (process ID) used by our application)
C). dumpsys meminfo <pid used by the Application>
Use this command to view memory usage.
If the chrome browser memory usage is:
We can constantly operate our applications to view memory usage in real time to locate problems.
Not for commercial purposes without permission
Welcome to the QQ Group Discussion: android Development Alliance:272209595
Android low memory system optimization software?
Your mobile phone is a low-storage device. If the third-party software is installed too much, the operation may be poor. You can download "android optimization master" for comprehensive cleaning. If you think this software occupies Memory, you are recommended to choose the "FMR Memory Cieaner" system optimization software. This software is small and only occupies KB of Memory, and the cleaning effect is particularly remarkable. The cell phone CPU usage is high or low, which is normal. (It is recommended that you replace GO desktop with a "dim sum desktop", which occupies moderate memory and can use an apple-like interface. It also comes with a system cleanup function)
The memory optimization software is good for Android phones.
The general memory optimization is to add a plug-in to kill the process. I recommend the toolbox to you. I will use it myself. I will be able to use the tool in dangle.com. This software is not only about memory optimization, there are also good functions such as scheduled scenarios and program management. Basically, it is enough to use the routine management of the software.