开发者

Does View.removeAllViews() release memory?

I experienced OutOfMemory exception in my code, so I am reviewing the code.

I have a question, does View.re开发者_开发百科moveAllViews() release the memory that were used by the child views that were previously added into this the parent view?

Thanks.


View.removeAllViews() might release the Views, and will schedule them for garbage collection (which could occur later) however you might still have a problem because @drawables in the XML or in your code with 'getDrawable()' could still consume memory.

I have struggled with OutOfMemory errors a lot myself and found that the biggest issue was not the Layout XML or the View objects, but the Drawables and Resources that they loaded (or I loaded to attach to them.)

A great talk on this can be found on YouTube from Google IO 2011:

http://www.youtube.com/watch?v=_CruQY55HOk

This talk introduces using the Eclipse MAT (Memory Analysis Tool) to troubleshoot OutOfMemory exceptions. I suggest it because you mention you're reviewing code and the best place to start looking for an OutOfMemory error is ... "what is taking up my memory?"


Except if your code has references on the ViewGroup's child views, all ViewGroup's child views should be "garbage collectable".

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜