简介:
我在一个有很多图像的android应用程序上工作。这些图像显示在几个回收站视图和查看寻呼机中。为了缓存图像,我使用Fresco,它在Application类中初始化如下:
Fresco.initialize(this, ImagePipelineConfig
.newBuilder(getApplicationContext())
.setBitmapMemoryCacheParamsSupplier(new BitmapMemoryCacheParamsSupplier(getApplicationContext()))
.setDownsampleEnabled(true)
.build());
当图像在RecyclerView中显示时,我使用SimpleDraweeView并按如下方式加载:
val imageRequest = ImageRequestBuilder
.newBuilderWithSource(Uri.parse(imageUrl))
.setResizeOptions(ResizeOptions(50, 10))
.build()
(itemView as SimpleDraweeView).setImageRequest(imageRequest)
还应注意,对于每个请求,为了避免内存缓存图像,将调用以下行
Fresco.getImagePipeline().evictFromMemoryCache(Uri.parse(imageUrl))
我还在使用ZoomableDraweeView的视图分页器中加载图像,在这种情况下,图像加载也是这样:
val view = ZoomableDraweeView(container.context)
view.setAllowTouchInterceptionWhileZoomed(true)
view.controller = Fresco.newDraweeControllerBuilder()
.setImageRequest(ImageRequestBuilder.newBuilderWithSource(Uri.parse(imageUrls[position]))
.setResizeOptions(ResizeOptions(50, 20)).build()).build()
对于这些请求,我避免使用内存缓存,而是使用
Fresco.getImagePipeline().evictFromMemoryCache(Uri.parse(imageUrls[position]))
还应注意,每次用户离开这些包含图片的活动时,我都会这样:
@Override
protected void onStop() {
super.onStop();
Fresco.getImagePipeline().clearMemoryCaches();
}
问题:
问题在于,在某些设备上滚动浏览这些图像时,我的应用因内存不足而崩溃
问题
有什么方法可以改善壁画设置,还是缺少我可以摆脱OOM的东西?
使用崩溃日志进行更新:
java.lang.OutOfMemoryError: Failed to allocate a 2833932 byte allocation with 1972896 free bytes and 1926KB until OOM
E at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
E at android.graphics.Bitmap.nativeCreate(Native Method)
E at android.graphics.Bitmap.createBitmap(Bitmap.java:975)
E at android.graphics.Bitmap.createBitmap(Bitmap.java:946)
E at android.graphics.Bitmap.createBitmap(Bitmap.java:913)
E at android.graphics.drawable.VectorDrawable$VectorDrawableState.createCachedBitmapIfNeeded(VectorDrawable.java:834)
E at android.graphics.drawable.VectorDrawable.draw(VectorDrawable.java:318)
E at android.graphics.drawable.LayerDrawable.draw(LayerDrawable.java:916)
E at com.facebook.drawee.drawable.ForwardingDrawable.draw(ForwardingDrawable.java:185)
E at com.facebook.drawee.drawable.ScaleTypeDrawable.draw(ScaleTypeDrawable.java:123)
E at com.facebook.drawee.drawable.FadeDrawable.drawDrawableWithAlpha(FadeDrawable.java:302)
E at com.facebook.drawee.drawable.FadeDrawable.draw(FadeDrawable.java:289)
E at com.facebook.drawee.drawable.ForwardingDrawable.draw(ForwardingDrawable.java:185)
E at com.facebook.drawee.generic.RootDrawable.draw(RootDrawable.java:81)