1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > android内存问题查看工具 哪些Android工具和方法最适合查找内存/资源泄漏?

android内存问题查看工具 哪些Android工具和方法最适合查找内存/资源泄漏?

时间:2020-09-20 06:55:35

相关推荐

android内存问题查看工具 哪些Android工具和方法最适合查找内存/资源泄漏?

如果您只是使用位图背景,那么@hp.android的答案很好,但是,在我的例子中,我有一个BaseAdapter提供一套ImageViewS代表aGridView..我修改了unbindDrawables()方法,以便条件是:if(viewinstanceofViewGroup&&!(viewinstanceofAdapterView)){

...}

但是问题是,递归方法从不处理AdapterView..为了解决这一问题,我做了以下工作:if(viewinstanceofViewGroup){

ViewGroupviewGroup=(ViewGroup)view;

for(inti=0;i

unbindDrawables(viewGroup.getChildAt(i));

if(!(viewinstanceofAdapterView))

viewGroup.removeAllViews();}

使孩子们AdapterView仍然被处理-该方法只是不尝试删除所有的子级(这是不支持的)。

然而,这并不能完全解决这个问题,因为ImageViewS管理一个不是他们背景的位图。因此,我补充如下。这并不理想,但有效:if(viewinstanceofImageView){

ImageViewimageView=(ImageView)view;

imageView.setImageBitmap(null);}

总体上unbindDrawables()方法是:privatevoidunbindDrawables(Viewview){

if(view.getBackground()!=null)

view.getBackground().setCallback(null);

if(viewinstanceofImageView){

ImageViewimageView=(ImageView)view;

imageView.setImageBitmap(null);

}elseif(viewinstanceofViewGroup){

ViewGroupviewGroup=(ViewGroup)view;

for(inti=0;i

unbindDrawables(viewGroup.getChildAt(i));

if(!(viewinstanceofAdapterView))

viewGroup.removeAllViews();

}}

我希望有一个更有原则的方法来释放这些资源。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。