kaya
kaya

Reputation: 55

Android-Activity- Should I set views to null on OnDestroy method?

Let's say I have recyclerView, and Adapter and a textview in my activity.

Should I set these to null on OnDestroy method like this:

@Override
protected void onDestroy() {
    super.onDestroy();
    recyclerView=null;
    adapter=null;
    textview=null
}

Or activity does this for me?

Edit: This is my AsyncTask. I retrieve data from server.

ParseQuery<ParseUser> getUser = new ParseQuery<ParseUser>(ParseUser.class);
    getUser.whereEqualTo("username",usernameString);
    getUser.getFirstInBackground(new GetCallback<ParseUser>() {
        @Override
        public void done(ParseUser object, ParseException e) { 

        }
    });

Upvotes: 3

Views: 1280

Answers (1)

Bohdan Shvets
Bohdan Shvets

Reputation: 136

The short answer is - No, you do not need to set all references to null
onDestroy() is the last lifecycle method called before the activity object is destroyed. When an object is destroyed it automatically releases all references it holds.

Upvotes: 4

Related Questions