Soheil
Soheil

Reputation: 1706

completely free memory after the Activity is closed

I need to completely free the memory which was in use by an Activity when the user closes that Activity. will using

android:noHistory="true"

be enough?

Upvotes: 1

Views: 119

Answers (1)

Snicolas
Snicolas

Reputation: 38168

By saying

android:noHistory="true"

you tell android not to keep a reference of your activity inside the back stack of activities. That's already a good start.

The only thing that remains to be done is to be sure that you don't keep a reference yourself to your activity. For instance, don't :

  • store your activity's instance as a static data field. It would not be garbage collected as classes are not.
  • store your activity's instance as a data field of a singleton. (As transitively a singleton instance is a static data field). And so on.

If you don't keep any reference to it, and add the noHistory flag, then you can be sure it will be garbage collected.

Also, note that you can use MAT with eclipse to get sure that there is no instance of your first activity as soon as you reached the second activity.

Upvotes: 2

Related Questions