As we all knowProgramOOM is easy to appear, and most of the time is triggered by bitmap Decode:
Error/androidruntime (16350): Java. Lang. outofmemoryerror: bitmap size exceeds VM budget
We know that the memory of the android program is generally limited to 16 MB, of course there are also 24 MB, and the memory of the android program is divided into two parts: Native and Dalvik. Dalvik is what we usually call a Java heap, the objects we create are allocated here, while bitmap is allocated directly on native. The memory limit is that native + Dalvik cannot exceed the maximum limit.
Run the following command to view the memory usage of the program:
ADB shell dumpsys meminfo $ package_name or $ PID // use the package name or process ID of the program
Take the launcher program that comes with Android as an example:
Run: ADB shell dumpsys meminfo com. Android. Launcher
Results: Applications memory usage (Kb): uptime: 113017 realtime: 113017 ** meminfo in PID 129 [COM. android. launcher] ** native Dalvik other total size: 4572 3527 N/A 8099 allocated: 4113 2684 N/A 6797 free: 406 843 N/A 1249 (PSS ): 1775 3572 3953 9300 (shared dirty): 1448 4020 4792 10260 1652 (priv dirty): 1308 708 3668 objects views: 0 viewroots: 0 appcontexts: 0 activities: 0 assets: 5 assetmanagers: 5 Local binders: 14 proxy binders: 21 death recipients: 0 OpenSSL sockets: 0 SQL heap: 64 memoryused: 64 bytes: 4 largestmemalloc: 50 databases pagesize dbsize lookaside dbname 1024 4 48 launcher. DB
For details about what each item represents, refer:
Native Dalvik other total size: 4572 3527 N/A 8099 allocated: 4113 2684 N/A 6797
The size is the required memory, and the allocated is the allocated memory. The corresponding two columns are native and Dalvik, respectively, oom may occur when the total number, that is, the total column, exceeds the maximum memory limit of a single program.
Most of the time, oom operations are related to images. The following are some suggestions to minimize this situation:
1. decode bitmap, configure options as much as possible. For example, after insamesize2.bitmap is used up, call bitmap. recycle () to release memory 3. if the application is an image-based application, when lazyload and dymanicrecycle4.decode bitmap are used as much as possible, decodeCodeTry catch out and catch OOM error to avoid program crash. You can do some memory release operations in catch.