title: Large number of items in RecyclerView.Adapter - Memory Issue
body: <p><strong>Overview</strong>: I'm having a chat application. Till now, I was using CursorAdapter with a Listview to load my chat items in the list. But now, I'm planning to refactor the code to use RecyclerView with RecyclerView.Adapter and a "Load More" functionality like whatsapp. </p>
  
  <p><strong>Issue</strong>: Memory consumption. With CursorAdapter, items not in viewable area were getting Garbage Collected, but now since I'm using an ArrayList of my CustomModal, once you load all the items in the list (by clicking on the "Load More" button) I'm seeing high memory consumption in the memory logs (No Garbage Collection). </p>
  
  <p>My guess is now, I'm loading all the items in an ArrayList and that is causing the issue. Is that it? </p>
  
  <p>Is there a way to avoid the issue or optimize the problem?</p>
  
  <p><strong><em>EDIT</em></strong>:
  Can't post the complete code here, but here is a snippet of the kind of Adapter that I've implemented:</p>
  
  <pre><code>public class MessageAdapter extends RecyclerView.Adapter&lt;MessageAdapter.MyViewHolder&gt; {
  
      private ArrayList&lt;MyModal&gt; mMyModals;
  
      public MessageAdapter(ArrayList&lt;MyModal&gt; mMyModals) {
          this.mMyModals = mMyModals;
          //... Some fields initialization here
      }
  
      public void changeList(ArrayList&lt;MyModal&gt; myModals, boolean isLoadMoreEnabled){
          this.mMyModals = myModals;
          //... Some fields initialization here
          notifyDataSetChanged();
      }
  
      public void toggleLoadMore(boolean isLoadMoreEnabled){
          if(isLoadMoreEnabled){
              //..Checks if load more is already enabled or not
              //..If not then enables it by adding an item at 0th poition of MyModal list
              //..Then notifyDataSetChanged()
          }else{
              //..Checks if load more is already disabled or not
              //..If not then disables it by removing an item at 0th poition of MyModal list
              //..Then notifyDataSetChanged()
          }
      }
  
      @Override
      public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          MyViewHolder messageViewHolder = null;
          View itemLayoutView = null;
  
          MyModal.MessageType messageType = MyModal.MessageType.getMessageTypeFromValue(viewType);
          switch (messageType){
              case MESSAGE_TYPE1:
                  itemLayoutView = LayoutInflater.from(parent.getContext())
                          .inflate(R.layout.layout1, null);
                  messageViewHolder = new Type1ViewHolder(itemLayoutView);
                  break;
              case MESSAGE_TYPE2:
                  itemLayoutView = LayoutInflater.from(parent.getContext())
                          .inflate(R.layout.layout2, null);
                  messageViewHolder = new Type2ViewHolder(itemLayoutView);
                  break;
          }
  
          return messageViewHolder;
      }
  
      @Override
      public void onBindViewHolder(MyViewHolder holder, int position) {
          final MyModal myModal = mMyModals.get(position);
          MyModal.MessageType messageType = myModal.getMessageType();
          holder.initialize(myModal);
      }
  
      @Override
      public int getItemCount() {
          return (mMyModals != null)?mMyModals.size():0;
      }
  
      @Override
      public int getItemViewType(int position) {
          return mMyModals.get(position).getMessageType().getValue();
      }
  
      public abstract class MyViewHolder extends RecyclerView.ViewHolder {
  
          public MyViewHolder(View itemLayoutView) {
              super(itemLayoutView);
          }
  
          public abstract void initialize(MyModal myModal);
      }
  
      class Type1ViewHolder extends MyViewHolder {
  
          //...Variables
  
          public Type1ViewHolder(View itemLayoutView) {
              super(itemLayoutView);
              //...variables initialization here
          }
  
          @Override
          public void initialize(MyModal myModal) {
              //...Setting values in view using myModal
          }
      }
  
      class Type2ViewHolder extends MyViewHolder {
  
          //...Variables
  
          public TextViewHolder(View itemLayoutView) {
              super(itemLayoutView);
              //...variables initialization here
          }
  
          @Override
          public void initialize(MyModal myModal) {
              //...Setting values in view using myModal
          }
      }
  }
  </code></pre>