aryaxt
aryaxt

Reputation: 77646

Android ==> Mmory Management Questions?

My question are commented in the code

ImageView img = new ImageView();
this.layout.addView(img);
MyObject o = new Object(img);
// Do i need to set img to null?

ArrayList <MyObject> myArray = new ArrayList <MyObject>();
MyObject obj = new MyObject();
myArray.add(obj);
// Do i need to set obj to null?

Upvotes: 0

Views: 184

Answers (2)

Andrey Chorniy
Andrey Chorniy

Reputation: 81

You can find a lot of useful tips here (Designing for Performance.) regarding memory, performance in Android. And for sure, you don't need to set variables to null in your code

Upvotes: 0

fadden
fadden

Reputation: 52353

Why would you need to set it to null?

If you're worried about garbage collection, the reference ceases to exist as soon as the local variable is reassigned or goes out of scope. (It's not quite that simple, but that's the general idea.)

Upvotes: 1

Related Questions