The memory of the android program is divided into two parts: Native and Dalvik. Dalvik is the Java heap we usually call. The objects we create are allocated here, bitmap is directly allocated on native. The memory limit is that native + Dalvik cannot exceed the maximum limit. The memory size of Android programs is generally limited to 16 MB, of course there are also 24 MB. 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 as an example:
For details about what each item represents, refer:
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, insamplesize;2After using bitmap, call Bitmap. Recycle () to release memory; 3If the application is an image-based application, use lazyload and dymanicrecycle as much as possible; 4. Decode When bitmap is used, decodetrycatchCome out,catchOOM To avoid program crash, you cancatchTo release the memory; http://stackoverflow.com/questions/2298208/how-to-discover-memory-usage-of-my-application-in-android/2299813#2299813;
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.