title: Correct way of using adapter with Glide
body: <p>When loading about 40 images (resolution 1080x1920) with Glide , I am getting out of memory errors while I am scrolling trough my RecyclerView. I am using small thumbnails on my gallery to fill up images.</p>
  
  <p>Is this the correct way to use Glide in an Adapter ? :</p>
  
  <pre><code>public class GalleryAdapter extends RecyclerView.Adapter&lt;GalleryAdapter.MyViewHolder&gt; {
  
  private List&lt;String&gt; images;
  private Context mContext;
  public class MyViewHolder extends RecyclerView.ViewHolder {
      public ImageView thumbnail;
  
      public MyViewHolder(View view) {
          super(view);
          thumbnail = (ImageView) view.findViewById(R.id.thumbnail);
      }
  }
  
  
  public GalleryAdapter(Context context, List&lt;String&gt; images) {
      mContext = context;
      this.images = images;
  }
  
  @Override
  public int getItemViewType(int position) {
      return position;
  }
  
  @Override
  public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
      View itemView = LayoutInflater.from(parent.getContext())
              .inflate(R.layout.gallery_thumbnail, parent, false);
  
      return new MyViewHolder(itemView);
  }
  
  @Override
  public void onBindViewHolder(final MyViewHolder holder, int position) {
      final String image = images.get(position);
  
      Glide.with(mContext).load(image).asBitmap().format(DecodeFormat.PREFER_RGB_565).diskCacheStrategy(DiskCacheStrategy.ALL).thumbnail(0.1f).centerCrop().placeholder(R.drawable.ac_icon_300).dontAnimate().into(new SimpleTarget&lt;Bitmap&gt;() {
          @Override
          public void onResourceReady(Bitmap resource, GlideAnimation&lt;? super Bitmap&gt; glideAnimation) {
              holder.thumbnail.setImageBitmap(resource);
  
  
          }
      });
  
  
  }
  
  @Override
  public int getItemCount() {
      return images.size();
  }
  
  public interface ClickListener {
      void onClick(View view, int position);
  
      void onLongClick(View view, int position);
  }
  
  public static class RecyclerTouchListener implements RecyclerView.OnItemTouchListener {
  
      private GestureDetector gestureDetector;
      private GalleryAdapter.ClickListener clickListener;
  
      public RecyclerTouchListener(Context context, final RecyclerView recyclerView, final GalleryAdapter.ClickListener clickListener) {
          this.clickListener = clickListener;
          gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
              @Override
              public boolean onSingleTapUp(MotionEvent e) {
                  return true;
              }
  
              @Override
              public void onLongPress(MotionEvent e) {
                  View child = recyclerView.findChildViewUnder(e.getX(), e.getY());
                  if (child != null &amp;&amp; clickListener != null) {
                      clickListener.onLongClick(child, recyclerView.getChildPosition(child));
                  }
              }
          });
      }
  
      @Override
      public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
  
          View child = rv.findChildViewUnder(e.getX(), e.getY());
          if (child != null &amp;&amp; clickListener != null &amp;&amp; gestureDetector.onTouchEvent(e)) {
              clickListener.onClick(child, rv.getChildPosition(child));
          }
          return false;
      }
  
      @Override
      public void onTouchEvent(RecyclerView rv, MotionEvent e) {
      }
  
      @Override
      public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
  
      }
    }
  }
  </code></pre>
  
  <p>Recyclerview : </p>
  
  <pre><code>    images = getData();
      recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
      mAdapter = new GalleryAdapter(getApplicationContext(), images);
  
      RecyclerView.LayoutManager mLayoutManager = new    GridLayoutManager(getApplicationContext(), 3);
      recyclerView.setLayoutManager(mLayoutManager);
      recyclerView.setItemAnimator(new DefaultItemAnimator());
      recyclerView.setAdapter(mAdapter);
  </code></pre>
  
  <p>Error : </p>
  
  <pre><code>Caused by: java.lang.OutOfMemoryError: Failed to allocate a 4147212 byte allocation with 34056 free bytes and 33KB until OOM  at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
  </code></pre>