Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 629 (example.testpro)

Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 629 (example.testpro)

产生原因:编写Android程序有需要加载大量图片(同次出现30张左右图片)造成的程序闪退。

错误提示:

原因
报错信息

解决方法:

原文:

The real error is Out of memory on a 23818256-byte allocation. You are attempting to allocate a ~22MB block of memory, and you do not have that much free memory available, let alone a contiguous block that large.

In this case, this is coming from a drawable resource. ~22MB would be a truly massive image, more like 2400x2400 than 1200x1200.

Your process heap size is 48MB, which is substantial, but ~22MB is almost half your heap budget.


I would recommend that you find out which drawable resource this is (looks like it might be a background of a RelativeLayout), then reduce its size and the sizes of similar images. Here, by “size” I mean total pixel count, not the on-disk size, as what matters is the decompressed size in RAM, not how big the image is on disk.

Also, this might be an issue of resource directories. For example, if you put your 1200x1200 image in res/drawable/, that effectively is synonymous with res/drawable-mdpi/. If this device happens to be an -xhdpi device, then that would explain the memory usage, as Android will try to upsample this image and double each of the dimensions.

原文链接: Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 32140

大意:

主要说明图片所占 **巨大** 内存造成的内存溢出,是程序闪退的原因

解决方法:

主要提供两种方法:
  1. 通过降低图片的像素,例如将原1200*1200的图片降低为200*200, 目的是为了降低在RAM中解压后体积。
  2. 通过适配屏幕分辨率的图片放置位置,例如1200*1200像素的图片放置在-mdpi/,而设备为 -xhdpi 分辨率,则Android会尝试上传并将它的每个纬度扩张1倍.

由于只是一个demo,我所使用所以只是简单的将所有图片在每个 drawable/ 下放置一份。

可以看到图片的要占内存大大减小

之后的结果

事实上如果要尝试正确匹配,应当了解不同分辨率下屏幕图片的要求,特别是在平板 与 手机端都需要兼容的情况下。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值