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 When configuring. Decode bitmap, try to configure options, for example, insamesize.
|
|
2 After using bitmap, call bitmap. Recycle () to release the memory.
|
|
3 If the application is an image-based application, use lazyload and dymanicrecycle whenever possible.
|
|
4 . Decode bitmap
try catch
Come out, catch Oom error to avoid program crash.
catch It does some memory release operations |
Http://stackoverflow.com/questions/2298208/how-to-discover-memory-usage-of-my-application-in-android/2299813#2299813