Java에서 메모리 누수의 기본 개념을 이해합니다 (즉, 불필요한 객체는 여전히 다른 객체에 의해 참조되고 GCed 될 수 없음).안드로이드 윈도우 누출 동안 내부적으로 어떤 일이 발생합니까?
어떻게이 개념을 Android의 WindowLeaked
예외로 매핑 할 수 있습니까?
예를 들어, AsyncTask
실행 중에 방향을 변경하면 다음 코드로 인해 WindowLeaked
예외가 발생합니다. 이 경우 개체가 여전히 보유하고있는 개체는 불필요한 개체를 참조합니다. ProgressDialog
또는 Activity
?
public class WindowLeakedTestActivity extends AppCompatActivity {
...
static class MyTask extends AsyncTask<Void, Void, String> {
Context context;
private ProgressDialog mProgress;
public MyTask(Context c) {
context = c;
}
protected void onPreExecute() {
super.onPreExecute();
mProgress = ProgressDialog.show(context, "hello world", "wait", true, true);
}
protected String doInBackground(Void... params) {
try {
Thread.sleep(8000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return "";
}
}
}
답변 해 주셔서 감사합니다. 왜 '활동'이 파괴되면 '진전 대화'가 유출되는 것일까? – JackWM
http://stackoverflow.com/a/21986772/966550 – waqaslam
좋은 링크. 그러나 누가 GC 진행할 수 없도록 'progressdialog'에 대한 참조를 보유하고 있는지 누가 대답하지 않습니다. – JackWM