I read the link at http://developer.android.com/resources/articles/avoiding-memory-leaks.html
and need to know what should be done if I create a button
Button button = new Button(this) in an activity
and assign the button to a static variable “sButton”
sButton = button
What should be done in the onDestroy() method of the activity to avoid memory leakage.Will assigning sButton=null do the job sufficiently?Or do we have to call some other methods on sButton.
Suppose we do the same thing as above but instead of button we save the activity class itself or activity context to a static variable,what should be done so that to delete all reference of the activity so that the activity could be destroyed properly incase of memory shortage.
The example states that doing this with a simple drawable will leak the entire activity because of a chain of references. If you, instead of saving the drawable, save the activity you fall into the same problem.
Setting the reference to null should solve the problem, look for the exampled cited in the article. But beware of keeping an unneeded activity in memory.