如何避免 OutOfMemoryError

how to avoid OutOfMemoryError

我正在尝试在每个水平列表视图中加载 20 张图像。我的 RecyclerView 包含 7 个水平 Listview,每个 Listview 包含 20 Images.When 我单击任何 Listview 以获取图像详细信息并返回 press.while 我继续此步骤 4 次然后出现内存不足错误。

如何避免内存不足错误?

你也可以推荐一下,

  1. 哪个图像加载器最适合一次加载大量图像而无需 占用大量运行时内存。
  2. 包含高分辨率图像的 ListView 的缩小图像。

不确定是否对您有帮助,但请尝试此代码

  @Override
public void onLowMemory() {
    super.onLowMemory();
    System.gc(); // clear bitmap and other objects here to reduce memory. 
}