One: Dalvik virtual machine
For Android platforms, the Dalvik JAVAVM used by its hosting layer has many things to optimize for its current performance, such as the possibility of manually interfering with GC processing in the development of some large-scale games or resource-consuming applications, using The Settargetheaputilization method provided by the Dalvik.system.VMRuntime class can enhance the processing efficiency of the program heap memory. Of course, the specific principle we can refer to open source Engineering, here we only say how to use:
Private final static floattarget_heap_utilization = 0.75f;
You can call Vmruntime.getruntime () when the program OnCreate. Settargetheaputilization (target_heap_utilization); Can.
In addition to optimizing heap memory allocations for Dalvik virtual machines, we can also enforce our own software's memory size, using the Dalvik.system.VMRuntime class provided by Dalvik to set the minimum heap memory as an example:
- Private final static int cwj_heap_size = 6* 1024* 1024x768;
- Vmruntime.getruntime (). Setminimumheapsize (Cwj_heap_size);
Sets the minimum heap memory size to 6MB.
Two: Bitmap
When using bitmap in Android, it is easy to overflow memory and report the following error: Java.lang.OutOfMemoryError:bitmap size exceeds VM budget
- Bitmapfactory.options Options = new Bitmapfactory.options ();
- Options.insamplesize = 2;
Changing the image size does not remove the overflow error. You can use the Recycle () method to show that the GC recycles a bitmap object, usually for a bitmap that is not used in the following way
if (bitmapobject.isrecycled () = =false) //If not recycled
Bitmapobject.recycle ();