public class TestActivity extends Activity {
public static TestActivity mTestActivity;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mTestActivity = this;
}
@Override
protected void onDestroy() {
mTestActivity = null;
super.onDestroy();
}
}
Can I ask a very rookie question?
Does static link to Activity ALWAYS leads to memory leak? Even if I ‘null’ it on destroy?
EDIT:
If there is a memory leak even though you ‘null’ it on destroy, could you explain why?
I have some years of Java experience but I cannot understand why ‘null’ on destroy does not free the memory.
If, you null it on destroy there is not point in keeping it static. As for the leak, yes, I think you will (if you change activities). It would be easier to just keep a (non-static) reference to the application.