将图像加载到内存时出现内存不足错误

时间:2013-05-01 13:27:12

标签: android android-drawable

我正在将多个图片加载到我的应用中。我必须加载它们以使用我的动画。

    ArrayList<AnimationsCls> animArr = new ArrayList<AnimationsCls>(); 

    for (int i = 0; i < 3; i++)
             animArr.add(new AnimationsCls());

    for (int j = 1; j <= numOfimages; j++) 
        animArr.get(0).f_anim.addFrame(Drawable.createFromPath(path+"/Sites/Site6/Zoom1/Zoom"+j+".jpg"), i);    

    for (int j = 1; j <= numOfimages; j++) 
        animArr.get(1).f_anim.addFrame(Drawable.createFromPath(path+"/Landscape/Sequence10/Landscape_WB_"+j+".jpg"), i);    

    for (int j = 1; j <= numOfimages; j++) 
        animArr.get(2).f_anim.addFrame(Drawable.createFromPath(path+"/Sites/Site2/Zoom1/Zoom"+j+".jpg"), i);    


    public class AnimationsCls
    {
    AnimationDrawable f_anim = new AnimationDrawable();
    //AnimationDrawable b_anim = new AnimationDrawable();
    boolean active;
    }

问题是,对于3个动画数组,内存是sufucuent,但如果我添加更多,我的内存不足。我已经通过Photoshop编辑图像到最小尺寸,每个图像权重输出90kb。已经为清单添加了大堆。如何在不释放图像的情况下缩小内存中图像的大小?

我在DDMS中的记忆:

05-01 15:58:29.775: I/dalvikvm-heap(13768): Grow heap (frag case) to 9.963MB for 3686416-byte allocation
05-01 15:58:32.015: I/dalvikvm-heap(13768): Grow heap (frag case) to 13.508MB for 3686416-byte allocation
05-01 15:58:32.285: I/dalvikvm-heap(13768): Grow heap (frag case) to 17.287MB for 3686416-byte allocation
05-01 15:58:32.395: I/dalvikvm-heap(13768): Grow heap (frag case) to 20.802MB for 3686416-byte allocation
05-01 15:58:32.495: I/dalvikvm-heap(13768): Grow heap (frag case) to 24.318MB for 3686416-byte allocation
05-01 15:58:32.595: I/dalvikvm-heap(13768): Grow heap (frag case) to 27.834MB for 3686416-byte allocation
05-01 15:58:32.695: I/dalvikvm-heap(13768): Grow heap (frag case) to 31.350MB for 3686416-byte allocation
05-01 15:58:32.795: I/dalvikvm-heap(13768): Grow heap (frag case) to 34.867MB for 3686416-byte allocation
05-01 15:58:32.895: I/dalvikvm-heap(13768): Grow heap (frag case) to 38.382MB for 3686416-byte allocation
05-01 15:58:33.005: I/dalvikvm-heap(13768): Grow heap (frag case) to 41.898MB for 3686416-byte allocation
05-01 15:58:33.095: I/dalvikvm-heap(13768): Grow heap (frag case) to 45.415MB for 3686416-byte allocation
05-01 15:58:33.195: I/dalvikvm-heap(13768): Grow heap (frag case) to 48.930MB for 3686416-byte allocation
05-01 15:58:33.295: I/dalvikvm-heap(13768): Grow heap (frag case) to 52.447MB for 3686416-byte allocation
05-01 15:58:33.395: I/dalvikvm-heap(13768): Grow heap (frag case) to 55.962MB for 3686416-byte allocation
05-01 15:58:33.495: I/dalvikvm-heap(13768): Grow heap (frag case) to 59.479MB for 3686416-byte allocation
05-01 15:58:33.615: I/dalvikvm-heap(13768): Grow heap (frag case) to 62.996MB for 3686416-byte allocation
05-01 15:58:33.715: I/dalvikvm-heap(13768): Grow heap (frag case) to 66.511MB for 3686416-byte allocation
05-01 15:58:33.825: I/dalvikvm-heap(13768): Grow heap (frag case) to 70.027MB for 3686416-byte allocation
05-01 15:58:33.935: I/dalvikvm-heap(13768): Grow heap (frag case) to 73.543MB for 3686416-byte allocation
05-01 15:58:34.045: I/dalvikvm-heap(13768): Grow heap (frag case) to 77.059MB for 3686416-byte allocation
05-01 15:58:34.145: I/dalvikvm-heap(13768): Grow heap (frag case) to 80.576MB for 3686416-byte allocation
05-01 15:58:34.255: I/dalvikvm-heap(13768): Grow heap (frag case) to 84.091MB for 3686416-byte allocation
05-01 15:58:34.355: I/dalvikvm-heap(13768): Grow heap (frag case) to 87.608MB for 3686416-byte allocation
05-01 15:58:34.465: I/dalvikvm-heap(13768): Grow heap (frag case) to 91.124MB for 3686416-byte allocation
05-01 15:58:34.565: I/dalvikvm-heap(13768): Grow heap (frag case) to 94.639MB for 3686416-byte allocation
05-01 15:58:34.675: I/dalvikvm-heap(13768): Grow heap (frag case) to 98.156MB for 3686416-byte allocation
05-01 15:58:34.775: I/dalvikvm-heap(13768): Grow heap (frag case) to 101.671MB for 3686416-byte allocation
05-01 15:58:34.885: I/dalvikvm-heap(13768): Grow heap (frag case) to 105.188MB for 3686416-byte allocation
05-01 15:58:35.005: I/dalvikvm-heap(13768): Grow heap (frag case) to 108.860MB for 3850256-byte allocation
05-01 15:58:35.135: I/dalvikvm-heap(13768): Grow heap (frag case) to 112.533MB for 3850256-byte allocation
05-01 15:58:35.245: I/dalvikvm-heap(13768): Grow heap (frag case) to 116.205MB for 3850256-byte allocation
05-01 15:58:35.365: I/dalvikvm-heap(13768): Grow heap (frag case) to 119.877MB for 3850256-byte allocation
05-01 15:58:35.475: I/dalvikvm-heap(13768): Grow heap (frag case) to 123.549MB for 3850256-byte allocation
05-01 15:58:35.605: I/dalvikvm-heap(13768): Grow heap (frag case) to 127.222MB for 3850256-byte allocation
05-01 15:58:35.715: I/dalvikvm-heap(13768): Grow heap (frag case) to 130.894MB for 3850256-byte allocation
05-01 15:58:35.825: I/dalvikvm-heap(13768): Grow heap (frag case) to 134.566MB for 3850256-byte allocation
05-01 15:58:35.935: I/dalvikvm-heap(13768): Grow heap (frag case) to 138.239MB for 3850256-byte allocation
05-01 15:58:36.035: I/dalvikvm-heap(13768): Grow heap (frag case) to 141.911MB for 3850256-byte allocation
05-01 15:58:36.145: I/dalvikvm-heap(13768): Grow heap (frag case) to 145.583MB for 3850256-byte allocation
05-01 15:58:36.245: I/dalvikvm-heap(13768): Grow heap (frag case) to 149.255MB for 3850256-byte allocation
05-01 15:58:36.365: I/dalvikvm-heap(13768): Grow heap (frag case) to 152.928MB for 3850256-byte allocation
05-01 16:19:11.075: I/dalvikvm-heap(13768): Grow heap (frag case) to 152.960MB for 3686416-byte allocation
05-01 16:19:11.745: I/dalvikvm-heap(13768): Grow heap (frag case) to 156.573MB for 3686416-byte allocation
05-01 16:19:11.975: I/dalvikvm-heap(13768): Grow heap (frag case) to 160.088MB for 3686416-byte allocation
05-01 16:19:12.175: I/dalvikvm-heap(13768): Grow heap (frag case) to 163.605MB for 3686416-byte allocation
05-01 16:19:12.415: I/dalvikvm-heap(13768): Grow heap (frag case) to 167.121MB for 3686416-byte allocation
05-01 16:19:12.595: I/dalvikvm-heap(13768): Grow heap (frag case) to 170.637MB for 3686416-byte allocation
05-01 16:19:12.805: I/dalvikvm-heap(13768): Grow heap (frag case) to 174.153MB for 3686416-byte allocation
05-01 16:19:12.995: I/dalvikvm-heap(13768): Grow heap (frag case) to 177.669MB for 3686416-byte allocation
05-01 16:19:13.195: I/dalvikvm-heap(13768): Grow heap (frag case) to 181.185MB for 3686416-byte allocation
05-01 16:19:13.375: I/dalvikvm-heap(13768): Grow heap (frag case) to 184.701MB for 3686416-byte allocation
05-01 16:19:13.555: I/dalvikvm-heap(13768): Grow heap (frag case) to 188.217MB for 3686416-byte allocation
05-01 16:19:13.725: I/dalvikvm-heap(13768): Grow heap (frag case) to 191.733MB for 3686416-byte allocation
05-01 16:19:13.905: I/dalvikvm-heap(13768): Grow heap (frag case) to 195.250MB for 3686416-byte allocation
05-01 16:19:14.085: I/dalvikvm-heap(13768): Grow heap (frag case) to 198.765MB for 3686416-byte allocation
05-01 16:19:14.315: I/dalvikvm-heap(13768): Grow heap (frag case) to 202.282MB for 3686416-byte allocation
05-01 16:19:14.525: I/dalvikvm-heap(13768): Grow heap (frag case) to 205.798MB for 3686416-byte allocation
05-01 16:19:14.755: I/dalvikvm-heap(13768): Grow heap (frag case) to 209.314MB for 3686416-byte allocation
05-01 16:19:15.005: I/dalvikvm-heap(13768): Grow heap (frag case) to 212.830MB for 3686416-byte allocation
05-01 16:19:15.205: I/dalvikvm-heap(13768): Grow heap (frag case) to 216.346MB for 3686416-byte allocation
05-01 16:19:15.415: I/dalvikvm-heap(13768): Grow heap (frag case) to 219.862MB for 3686416-byte allocation
05-01 16:19:15.615: I/dalvikvm-heap(13768): Grow heap (frag case) to 223.378MB for 3686416-byte allocation
05-01 16:19:15.815: I/dalvikvm-heap(13768): Grow heap (frag case) to 226.894MB for 3686416-byte allocation
05-01 16:19:16.025: I/dalvikvm-heap(13768): Grow heap (frag case) to 230.411MB for 3686416-byte allocation
05-01 16:19:16.255: I/dalvikvm-heap(13768): Grow heap (frag case) to 233.926MB for 3686416-byte allocation
05-01 16:19:16.475: I/dalvikvm-heap(13768): Grow heap (frag case) to 237.442MB for 3686416-byte allocation
05-01 16:19:16.655: I/dalvikvm-heap(13768): Grow heap (frag case) to 240.958MB for 3686416-byte allocation
05-01 16:19:16.855: I/dalvikvm-heap(13768): Grow heap (frag case) to 244.474MB for 3686416-byte allocation
05-01 16:19:17.085: I/dalvikvm-heap(13768): Grow heap (frag case) to 247.991MB for 3686416-byte allocation
05-01 16:19:17.305: I/dalvikvm-heap(13768): Forcing collection of SoftReferences for 3686416-byte allocation
05-01 16:19:17.345: E/dalvikvm-heap(13768): Out of memory on a 3686416-byte allocation.

0 个答案:

没有答案