在我们的程序中使用大量图像,我们在eyery Activity和Fragment中取消绑定,如下所示
protected void unbindDrawables(View view) {
if (view != null) {
if (view.getBackground() != null) {
view.getBackground().setCallback(null);
}
if (view instanceof ImageView) {
ImageView imageView = (ImageView) view;
imageView.setImageDrawable(null);
}
if (view instanceof ViewGroup && !(view instanceof AdapterView)) {
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
unbindDrawables(((ViewGroup) view).getChildAt(i));
}
if (!(view instanceof AbsSpinner) && !(view instanceof AbsListView)) {
((ViewGroup) view).removeAllViews();
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
像这样/sf/answers/474534721/说,但我使用mat发现该位图也使用了大量内存而不是发布.
Class Name | Objects | Shallow Heap | …Run Code Online (Sandbox Code Playgroud)