AmiguelS
AmiguelS

Reputation: 855

Remove View from memory

I am using 4 views, defined in XMl, to perform an animation when the app starts, but after the animation is done, I would like to free the memory the bitmaps are using. How can I don this? As of now, when done, the views are set to GONE, but they still occupy memory.

Upvotes: 0

Views: 426

Answers (2)

Anitha Manikandan
Anitha Manikandan

Reputation: 1170

Try this, to free the memory.

bitmap.recycle();
bitmap = null;

Upvotes: 0

Giorgio Antonioli
Giorgio Antonioli

Reputation: 16214

You have to recycle bitmap and then you have to release memory allocated in the heap:

if (view.getBackground() != null) {
    try {
        view.getBackground().setCallback(null);
        ((BitmapDrawable) view.getBackground()).getBitmap().recycle();
        view.destroyDrawingCache();
        view.notifyAll();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

Upvotes: 1

Related Questions