开发者

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?


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.)


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜