8

メモリ不足に関する質問は既に尋ねられていますが、解決策が見つかりませんでした

Bitmap Factory でメモリ不足の例外が発生しました。

inSampleSize=1

だから私はそれをtry catch out of memory例外で囲んでいたが、それは悪い習慣だからだ

try{
   .........
   ......
}catch (OutOfMemoryError e)
            {}

メモリ不足の例外もキャッチされましたが、私の質問は、この例外がキャッチされた後です。

GC のヒープ メモリのクリアまたは再割り当て

解決策はありますか?

私が使う

System.gc();

役に立たない助けてください!!!!!!!!

not even Bitmap also for GridView Orientation 
i found this exception
Clamp target GC heap from 17.333MB to 16.000MB
Out of memory on a 140416-byte allocation.
4

1 に答える 1

11

3日間の闘争の後、これを使用してヒープメモリを増加させないための解決策を見つけました

私はすべての ImageView をこのように置き換えます

<com.example.util.SingleShotImageView
                    android:id="@+id/grid_image"
                    android:layout_width="170dp"
                    android:layout_height="240dp"
                    android:adjustViewBounds="true"
                    android:layout_centerInParent="true"
                     />

このクラスを使用して、onDetachedFromWindow 関数のイメージ ビットマップ ヒープ サイズをクリアします。

public class SingleShotImageView extends ImageView {

    public SingleShotImageView(Context context) {
        super(context);
    }

    public SingleShotImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public SingleShotImageView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onDetachedFromWindow () {
        setImageDrawable(null);
        setBackgroundDrawable(null);
        setImageBitmap(null);
        System.gc();
    }

}

今では正常に動作し、ヒープメモリが残っています

ヒープ (フラグメントの場合) を 11.719MB に拡張し、8192016 バイトの割り当てを行う

于 2013-09-03T07:04:02.347 に答える