java - Android - 释放位图的内存
问题描述
我认为这个问题经常被问到,但在我这样做之后
bitmap.release;
bitmap = null;
在片段的onDestroy中,使用的内存和以前一样多。
片段:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
initializeViews();
croppedBitmap = BitmapFactory.decodeFile("/.../0001.jpeg");
imageView.setImageBitmap(croppedBitmap);
fabCreate.setOnClickListener(...); //never called
}
@Override
public void onDestroy() {
clearMemory();
super.onDestroy();
}
void clearMemory(){
fabCreate.setOnClickListener(null);
imageView.setImageBitmap(null);
imageView = null;
croppedBitmap.recycle();
croppedBitmap = null;
java.lang.System.gc();
}
解决方案
推荐阅读
- regex - 是否可以使用正则表达式将一行添加到文件中的特定行组中?
- button - 使用树莓派将 GPIO 输入映射到键盘键,使用程序集
- keras - Keras Conv2D 参数顺序
- corda - 在 Corda 中,根据 Java 中的自定义模式字段查询状态
- css - 表单的 translateY 将 div 隐藏在其下,我无法将其移动到表单后显示
- arduino - ESP8266 编译后关机
- vbscript - 如何在iframe中自动单击VBScript中没有名称或ID的按钮
- java - 匕首输出java(char)134不起作用cp1252
- xml - SDT 按数字字段排序
- java - JAVA:如何根据属性值合并来自 arrayList 的对象?