From: http://www.apkbus.com/forum.php? MoD = viewthread & tid = 898. On the simulatorGalleryWhen the image is placedJava. Lang. outofmemoryerror: bitmap size exceeds VM budgetException: The image size exceeds the RAM memory. SimulatorRamRelatively small, only 8 M memory, when I put a large number of images (each more than 100 K), the above reasons appear. Since each image was previously compressed. ToBitmapWhen the RAM memory is exceeded, the size will increase. The specific solution is as follows: Java code: // Solve the problem of memory overflow during image loading // Options only saves the image size, not the image size to the memory Bitmapfactory. Options opts = new bitmapfactory. Options (); // Scale ratio. It is difficult to scale according to the prepared ratio. Its value indicates the zoom factor. In the SDK, it is recommended that its value be the exponential value of 2, the larger the value, the clearer the image. Opts. insamplesize = 4; Bitmap BMP = NULL; BMP = bitmapfactory. decoderesource (getresources (), mimageids [position], opts ); ... // Recycle BMP. Recycle ();The above solution is used, but this is not the perfect solution. For more information, see: Optimize heap memory allocation of Dalvik virtual machines For the Android platform,Dalvik Java VMFrom the current performance, there are still many areas to optimize processing. For example, we may consider Manual Interference in GC processing when developing large game or resource-consuming applications. Dalvik. system. vmruntimeClassSettargetheaputilizationThe method can enhance the processing efficiency of the program heap memory. Of course, we can refer to open-source projects for specific principles. Here we will only talk about the usage: Private Final Static float target_heap_utilization = 0.75f;In the programOncreateYou can callVmruntime. getruntime (). settargetheaputilization (target_heap_utilization );You can. You can also customize the size of the android heap memory. For some Android projects, the main cause of performance bottleneck is the memory management mechanism of Android. Currently, mobile phone manufacturers are stingy with Ram and are very sensitive to the impact of RAM on the Performance of software fluency, in addition to optimizing the heap memory allocation of the Dalvik virtual machine, we can also forcibly define the heap memory size of our software. We useDalvik. system. vmruntimeFor example: Private Final Static int cwj_heap_size = 6*1024*1024; Vmruntime. getruntime (). setminimumheapsize (cwj_heap_size );// Set the minimum heap memory size to 6 MB. Of course, for memory compression, manual GC interference can also be performed. |