I understand the basic concepts of memory leak in Java (i.e., some unneeded objects are still referred to by others and cannot be GCed).
How can I map this concept to the WindowLeaked
exception in Android?
For example, the following code would cause a WindowLeaked
exception when
changing the orientation during AsyncTask
execution. In this case, what
objects still hold references the unneeded ones? ProgressDialog
or the 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 "";
}
}
}