For Android memory Overflow This problem, small series is a headache! Here's the idea of making your own!
First memory references are divided into strong references, weak references, soft references, virtual references!
A strong reference is an instance reference that, according to the GC principle of Java, cannot be reclaimed automatically if there is a reference, so a strong reference must be =null after it is exhausted
Ex:object object = new Object ();
object = null;
Soft references are referenced on the basis of strong references, and are referenced using SoftReference, which is not recycled until the system is low on memory, and is not recycled at all, and is suitable for cache;
Ex
Object object = new Object ();
softreference<object> Objectsoft = new softreference<object> (Object);
A weak reference is an object that can be obtained at any time without affecting the GC
Ex
Object object = new Object ();
weakreference<object> objectweak = new weakreference<object> (Object);
A virtual reference is not meant to be, after a virtual reference is made, the result is always null by the Get method, and the virtual reference usually writes the referenced object into referent, except that the Get method returns the result as null.
Object object = new Object ();
phantomreference<object> objectphantom = new Phantomreference<object> (object,referencequeue);(reference queue)
Here can be explained that imagebitmap often appear memory overflow, not the phone memory is not enough, but because the mobile phone to the application allocated memory is not all memory, but there is a limit, where the picture is generally compressed.
Another problem, the Android application layer is written in Java, and his bottom is written by C, which will cause a problem, Java has an automatic recovery mechanism, and C language does not. So you need to manually catalytic the recovery mechanism if necessary!
Ex
if (bitmapobject.isrecycled () ==false) {
Bitmapobject.recycle ();
System.GC ();//reminder System timely recovery, PS: Just a reminder, will not be executed immediately
}
The above is a small series of superficial memory overflow of some views!
Some ideas for Android memory overflow