Article: http://developer.android.com/resources/articles/avoiding-memory-leaks.html
what
private static Drawable sBackground;
@Override
protected void onCreate(Bundle state) {
super.onCreate(state);
TextView label = new TextView(this);
label.setText("Leaks are bad");
if (sBackground == null) {
sBackground = getDrawable(R.drawable.large_bitmap);
}
label.setBackgroundDrawable(sBackground);
setContentView(label);
}
When Drawable is attached to the view, the view is set as a callback on the accessible.
That true drawable will hold this view as a callback,
public void setBackgroundDrawable(Drawable d) {
......
d.setCallback(this);
But when the screen orientation changes, the returned callback will reset as a new activity context. I think that the previous textView will be separated from the static spread, so that the text view and the corresponding activity will be reusable.
So can someone explain me in detail? Thank.
source
share