Change this dialog.cancel();
to dialog.dismiss();
The solution is to call dismiss()
on the Dialog
you created in NetErrorPage.java:114 before exiting the Activity
, e.g. in onPause()
.
Views have a reference to their parent Context
(taken from constructor argument). If you leave an Activity
without destroying Dialog
s and other dynamically created View
s, they still hold this reference to your Activity
(if you created with this as Context
: like new ProgressDialog(this)
), so it cannot be collected by the GC, causing a memory leak.