6

Why should I call dismiss() method for AlertDialog before Activity is destroyed? Something leaks, but what exactly? Why then PopupWindow can handle Activity destroying?

I've found in Android sources that each alert dialog creates window:

Window w = PolicyManager.makeNewWindow(mContext);

What does that mean? Why it cannot just use PhoneWindow obtained from activity?

ADDED

Say, AlertDialog references Context, Context references nothing, then GC should garbage collect both objects (as they are not referenced from 'outside'). What else has a reference to AlertDialog? In other words where is exactly memory leak?

se.solovyev
  • 1,901
  • 1
  • 16
  • 20

1 Answers1

1

Alertdialogs are attached to our activity using a id,This Link shows the activity of a alertdialog, once the alertdialog is displayed it is a seperate window (u set cancel false then u r forced to manage it) if it is running on back and your activity gets destroyed Every memory associated with it will be released including the id of the AlertDialog. Thats y the error pops up .I think its clear now.

Viswanath Lekshmanan
  • 9,945
  • 1
  • 40
  • 64