Android内存限制

 先摘一段Google的官方文档:

        Mobile devices typically have constrained system resources. Android devices can have as little as 16MB of memory available to a single application. The Android Compatibility Definition Document (CDD), Section 3.7. Virtual Machine Compatibility gives the required minimum application memory for various screen sizes and densities. Applications should be optimized to perform under this minimum memory limit. However, keep in mind many devices are configured with higher limits.

        大致意思是说Android设备为每个app分配16MB的内存空间,虽然厂商会更改rom,定制更高的单个App内存空间,但是开发者应该依据最小的内存限制即16MB控制内存开销。

        Android设备屏幕大小不一,分辨率低至320*240,高至1280*720,对图片的需求也不同。如果在UI中需要加载一副大图片,明智的做法是先获取屏幕的分辨率,然后再决定加载图片的大小。在一款低分辨率的设备上加载高分辨率图片除了增加内存消耗,别无他用。因为设备最大能展示的清晰度为本身的屏幕分辨率。所以,如果一个不需要放大图片的控件需要加载图片,最大只需要加载该控件本身宽高的图片即可。

       Given that you are working with limited memory, ideally you only want to load a lower resolution version in memory. The lower resolution version should match the size of the UI component that displays it. An image with a higher resolution does not provide any visible benefit, but still takes up precious memory and incurs additional performance overhead due to additional on the fly scaling.

猜你喜欢

转载自zanelee007.iteye.com/blog/1887512