大Bitmap导致Android-java.lang.OutOfMemoryError

问题描述

Android:java.lang.OutOfMemoryError: Failed to allocate a 23970828 byte allocation with 2097152 free bytes and 2MB until OOM

这个错误一般出现在:

当我们在XML文件中使用 android:src="@drawable/launch_bg" 配置资源图片属性时,如果使用了一个高分辨率的图片,那么在程序运行时就会OOM
或者在代码中动态加载展示一个超大的 Bitmap 时出现。

解决方案:

1. 对于Bitmap展示图片之前,应当先对图片进行尺寸压缩!

2. 在AndroidManifest.xml中配置,为App申请更多内存。

	OutOfMemoryError is the most common problem occured in android while especially dealing with bitmaps. This error is thrown by the Java Virtual Machine (JVM) when an object cannot be allocated due to lack of memory space and also, the garbage collector cannot free some space.

	As mentioned by Aleksey, you can add below entities in your manifest file android:hardwareAccelerated="false" , android:largeHeap="true" it will work for some environment's.

		<application
		    android:allowBa
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值