0

My problem is when i remove images from image View it remove image but when i monitor memory from android studio motorize tool it increasing memory i am using Garbage collector .but its not good practice .

help me out with different solution.

    private void cleanImages() {
        img1.setImageDrawable(null);
      }

 public void clickClean4(View view) {
        cleanImages();
        System.runFinalization();
        System.gc();
        Runtime.getRuntime().gc();
    }
Muneebq Ashfaq
  • 105
  • 1
  • 7
  • Calling `System.gc();` is ineffective. Please read [this](http://stackoverflow.com/questions/2414105/why-is-it-bad-practice-to-call-system-gc) and [this](https://developer.android.com/training/displaying-bitmaps/manage-memory.html) – SripadRaj Jul 13 '16 at 12:27
  • You only have to use imageView.setImageDrawable(null) – Bob Jul 13 '16 at 12:31
  • Bob.when i use imageView.setImageDrawable(null) only so it not release memory – Muneebq Ashfaq Jul 13 '16 at 12:57

1 Answers1

0

You need to not only setImageDrawable(null); , but also recycle the bitmap.

You can do this by

 if (!bitmapDrawable.getBitmap().isRecycled()) {
        bitmapDrawable.getBitmap().recycle();
    }

Hope it helps.

ZAFFY
  • 1
  • 5