title: Resizing images to fit into ViewPager, outOfMemory exception
body: <p>I've setup a viewPager which should show around 50 images with a resolution of 1500,2100px. The images are provided by the user self. So I need to downscale the images which I do with this bit of code:</p>
  
  <pre><code>WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
      Display display = wm.getDefaultDisplay();
      Point size = new Point();
      display.getSize(size);
      int width = size.x;
      int height = size.y;
      //imageFile is a string to the image location.
      Bitmap bm = BitmapFactory.decodeFile(imagefile);
      Bitmap scaledBitmap = Bitmap.createScaledBitmap(bm, width, height, true);
  </code></pre>
  
  <p>When the image is downscaled I add it to the viewpager in a arrayList which works perfectly with only a few images. But now I need to load in 50 images, how am I supposed to do this? I'm getting outOfMemory errors, even after I downscaled the images.</p>
  
  <p>The images are added with this code (to the ViewPager):</p>
  
  <pre><code>    @Override
  public Object instantiateItem(ViewGroup container, int position) {
      ImageView imageView = new ImageView(context);
      //int padding = context.getResources().getDimensionPixelSize(R.dimen.padding_medium);
      //imageView.setPadding(padding, padding, padding, padding);
      imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
      //imageView.setImageResource(pages.get(position));
      imageView.setImageBitmap(pages.get(position));
      ((ViewPager) container).addView(imageView, 0);
      return imageView;
  }
  </code></pre>
  
  <p>I hope to get a good suggestion. I was thinking myself of loading only a few images and adding them dynamicly, but I don't know how I can destroy loaded images once I don't need them anymore.
  I'm open to any suggestions!</p>