android 数组释放资源,Android的OutOfMemory解决

android:orientation="vertical"

android:background="@drawable/main_background"

android:id="@+id/mian_bg"

android:scaleType="fitXY"

android:gravity="center"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

android:layout_gravity="center"

android:src="@drawable/img_main_roll0"

android:id="@+id/main_cion"

android:layout_width="180dp"

android:layout_height="180dp"/>

先获取图片控件:

public ImageView p_w_picpathView;

public LinearLayout linearLayout;

p_w_picpathView=(ImageView)findViewById(R.id.main_cion);

linearLayout=(LinearLayout)findViewById(R.id.mian_bg);

应在次Activity销毁时释放

protected void onDestroy() {

super.onDestroy();

p_w_picpathView.setImageBitmap(null);//释放

linearLayout.setBackground(null);

System.gc();//通知进行回收

}

使用Bitmap记得不用时调用回收

bitmap.recycle();

总结:

无论你是在xml中布局使用了:

android:background   ,

还是在java代码中调用了:

setBackground( background );-------API16+

setBackgroundDrawable( background)--------API16-

setBackgroundResource( resid)

的方式去设置了背景图片.

使用的时候,请调用一下对应的方法:

setBackgroundResource和 android:background → setBackgroundResource(0);

setBackgroundDrawable( background) → setBackgroundDrawable (null)

setBackground ( background ) → setBackground ( null )

然后再onDestory中调用System.gc();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值