简体   繁体   English

通用图像加载器是否支持蜂窝之前的Android版本?

[英]Does universal-image loader support android versions prior to honeycomb?

I was wondering is the universal-image-loader ( Found Here ) is supporting versions prior to honeycomb. 我想知道通用图像加载器( Found Here )是支持蜂窝之前的版本。 Because versions prior to honeycomb have a separate native heap stack the memory used by the bitmaps does not count towards the VM heap. 由于蜂窝之前的版本具有单独的本机堆栈,因此位图使用的内存不会计入VM堆。

I'm developing an image intensive app that is using this lib and I did successfully use it on android ICS. 我正在开发一个使用此lib的图像密集型应用程序,我在android ICS上成功使用它。 Now I'm trying to lower the API requirements and I'm having some trouble staying away from the Out of Memory exceptions which make my app crash. 现在我正在尝试降低API要求,并且我在远离内存不足异常时遇到了一些麻烦,这些异常会导致我的应用程序崩溃。

Universal Image Loader supports 1.5+ Android versions. Universal Image Loader支持1.5+ Android版本。 UIL tries to prevent OOM by using of weak references and own logic for caching and reference cleaning. UIL尝试通过使用弱引用和自己的逻辑来阻止OOM进行缓存和引用清理。 For effective memory management in Android versions prior to 3.0 we need use Bitmap.recycle() to clear native memory. 为了在3.0之前的Android版本中进行有效的内存管理,我们需要使用Bitmap.recycle()来清除本机内存。 But UIL can't do it itself because it can't know when Bitmap is not visible and not referenced by anyone. 但是UIL不能自己做,因为它无法知道Bitmap何时不可见而且没有被任何人引用。

User should do recycling yourself, when he know that he can do it. 当用户知道他可以做到时,他应该自己回收。

Also there are some UIL configuration tuning is possible for preventing OOM. 还有一些UIL配置调整可以防止OOM。

PS: How to define if Bitmap is in UIL memory-cache: PS:如何定义Bitmap是否在UIL内存缓存中:

Bitmap bmp = ...;
boolean isBitmapInCache = false;
MemoryCacheAware<String, Bitmap> memoryCache = ImageLoader.getInstance().getMemoryCache();
for (String key : memoryCache.keys()) {
    if (bmp == memoryCache.get(key)) {
        isBitmapInCache = true;
        break;
    }
}

if (!isBitmapInCache) {
    // You can recycle bitmap
}

It should work, it computes bitmap size as: 它应该工作,它计算位图大小为:

 bitmap.getRowBytes() * bitmap.getHeight();

Which gives correct bitmap size regardless of it being on java or native heap. 无论是在java还是本机堆上,它都能提供正确的位图大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM