Skip to content Skip to sidebar Skip to footer

Android. Calling Dismiss On A Dialog

When you call dismiss() on a dialog, besides hiding it, does it also remove it from memory? Does it remove all the Objects that were placed inside the dialog, like ImageViews, Butt

Solution 1:

No, i believe that dismiss() just hides it.

Here is the reference

removeDialog(int) will clear the state.

Solution 2:

In java memory can only be free by Garbage Collector and you can only make all that object to be null so that garbage collector can collect memory to free.

Why do you need this? The entire point of Java is that it takes care of memory management for you. Do you have some obvious memory issues or something?

Solution 3:

The Google Android Developer Documentation say :

public void dismiss () : Since: API Level 1 Dismiss this dialog, removing it from the screen. This method can be invoked safely from any thread. Note that you should not override this method to do cleanup when the dialog is dismissed, instead implement that in onStop().

Solution 4:

Manually freeing memory is

  1. Not doable in Java. You can allocate memory with new, but the Garbage Collector takes care of freeing it

  2. A bad idea when you have a Garbage Collector trying to work behind.

dismiss() simply hides the dialog. Call removeDialog(int) to remove all the references to it and wait for the GC to kick in.

Post a Comment for "Android. Calling Dismiss On A Dialog"