3

Article: http://developer.android.com/resources/articles/avoiding-memory-leaks.html metioned that:

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 a Drawable is attached to a view, the view is set as a callback on the drawable.

That's true, drawable will hold that view as callback,

public void setBackgroundDrawable(Drawable d) {
        ......
            d.setCallback(this);

But when screen orientation changes, drawable's callback will be reset as the new activity context. I think the previous textView will be detached from the static drawble, so that textview and according activity became recyclable.

So could anyone explain me in details? Thanks.

4

0 回答 0