out of memory with image switcher android
<p>let's see how to explain this issue. I have 4 activities and 1 layout for all of them. The layout contains an image switcher and a gallery. These activities will show different images which i have in an Integer array. All these images are in the drawable folder. When i start the application everything is ok i can switch between the activities but after a while i get an out of memory exception when i scroll the gallery. I don't know how to solve this because i don't know where to start to look, there's no stack trace. the only thing i get is this: </p>

<pre><code>03-16 15:46:50.367: ERROR/dalvikvm-heap(23389): 847992-byte external allocation too large for this process.
03-16 15:46:50.367: ERROR/dalvikvm(23389): Out of memory: Heap Size=5255KB, Allocated=2833KB, Bitmap Size=18900KB
03-16 15:46:50.367: ERROR/GraphicsJNI(23389): VM won't let us allocate 847992 bytes
</code></pre>

<p>and here is the code i'm using:</p>

<pre><code>private ImageSwitcher mSwitcher;

    private Integer[] mThumbIds = {drawables here...};

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mSwitcher = (ImageSwitcher) findViewById(R.id.switcher);
        mSwitcher.setFactory(this);
        mSwitcher.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in));
        mSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out));

        Gallery g = (Gallery) findViewById(R.id.gallery);
        g.setAdapter(new BasicsAdapter(getApplicationContext(), mThumbIds));
        g.setOnItemSelectedListener(this);
    }

    public void onItemSelected(AdapterView&lt;?&gt; parent, View v, int position, long id) {
        mSwitcher.setImageResource(mThumbIds[position]);
    }

    public void onNothingSelected(AdapterView&lt;?&gt; parent) {
    }

    public View makeView() {
        ImageView i = new ImageView(this);
        i.setBackgroundColor(0xFF000000);
        i.setScaleType(ImageView.ScaleType.FIT_CENTER);
        i.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        return i;
    }
</code></pre>

<p><strong>this is my adapter class:</strong></p>

<pre><code>public View getView(int position, View convertView, ViewGroup parent) {
        ImageView i = new ImageView(mContext);

        i.setImageResource(mThumbIds[position]);
        i.setAdjustViewBounds(true);
        i.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        i.setBackgroundResource(R.drawable.i);
        return i;
    }
</code></pre>

<p>I don't know how to clean the heap, nor if the drawables from the previous activity are still on memory. How can i solve this issue?</p>

<p>Thanks in advance.</p>
