Andoid Memory leakage and andoid Leakage
1. android Memory leakage occurs because the allocated memory is recycled.
Public static LocalHelper getInstance (Context context ){
If (instance = null ){
Instance = new LocalHelper (context );
}
Return instance;
}
If you upload an Activity in contenx, the activity cannot be recycled after Acitivty is finished.
Because the static instance will continue to reference the activity, memory GC will not cause oom and Memory leakage.
2. Memory leakage caused by Handler
Memory leakage caused by Handler usage should be said to be the most common
We know that Handler, Message, and MessageQueue are all associated with each other.
If the Message sent by Handler is not processed, the Message and the Handler object sent by Handler will be held by the thread MessageQueue.
Because Handler is a TLS (Thread Local Storage) variable, the lifecycle and Activity are inconsistent.
Therefore, this implementation method is generally difficult to ensure that it is consistent with the life cycle of the View or Activity, so it is easy to cause the release to fail correctly.
We recommend that you use weak references, but it may be difficult to write activity. member variables!
3. When imageloader loads an image, if you use Rgb_565, you can reduce the memory consumption when loading the image. However, the uploaded image will be blurred. We recommend that you use imagesize,
options = new DisplayImageOptions.Builder()
.cacheInMemory(true)
.cacheOnDisk(false)
.bitmapConfig(Bitmap.Config.RGB_565)
.build();
ImageSize size = new ImageSize(getImageWidth(), getImageWidth());
ImageLoader. loadImage (localFile. getOriginalUri (), size, options, new SimpleImageLoadingListener (viewHolder. imageView ));
When imageload loads the source image, if the image is too large, we recommend that you use the number of threads as 1 because it is easy to oom when three threads are simultaneously loaded;
4. Remember to clear () the static collection class object ();