Q:

ViewPager animation outOfMemoryError

I have 5 SlidingTabs.  I want to place ViewPager animation in one of them. 
Fragment class:
public class AdFragment extends Fragment {

int[] mResources = {
        R.drawable.six,
        R.drawable.five,
        R.drawable.four,
        R.drawable.eight,
        R.drawable.one,
        R.drawable.two,
        R.drawable.three,
        R.drawable.seven,
        R.drawable.nine,
        R.drawable.ten,
};
int currentPage;
public AdFragment() {
    // Required empty public constructor
}
Timer swipeTimer;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_ad, container, false);
    CustomPagerAdapter mCustomPagerAdapter = new CustomPagerAdapter(getActivity(),mResources);

    final ViewPager mViewPager = (ViewPager) view.findViewById(R.id.pager);
    mViewPager.setAdapter(mCustomPagerAdapter);

    final Handler handler = new Handler();
    final Runnable Update = new Runnable() {
        public void run() {
            if (currentPage == mResources.length) {
                currentPage = 0;
            }
            mViewPager.setCurrentItem(currentPage++, true);
        }
    };

    swipeTimer = new Timer();
    swipeTimer.schedule(new TimerTask() {

        @Override
        public void run() {
            handler.post(Update);
        }
    }, 500, 3000);

    return view;
}

}
Adapter class:
class CustomPagerAdapter extends PagerAdapter {

Context mContext;
LayoutInflater mLayoutInflater;
int[] mResources;
private Resources resource;

public CustomPagerAdapter(Context context,int[] mResources) {
    mContext = context;
    mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context. LAYOUT_INFLATER_SERVICE);
    this.mResources = mResources;
}

@Override
public int getCount() {
    return mResources.length;
}

@Override
public boolean isViewFromObject(View view, Object object) {
    return view == ((LinearLayout) object);
}

@Override
public Object instantiateItem(ViewGroup container, int position) {
    View itemView = mLayoutInflater.inflate(R.layout.pager_item, container, false);

    ImageView imageView = (ImageView) itemView.findViewById(R.id.imageView);
    imageView.setImageResource(mResources[position]);

    container.addView(itemView);

    return itemView;
}

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
    container.removeView((LinearLayout) object);
}
@Override
public Object instantiateItem(View view, int position) {
    ImageView myView = new ImageView(mContext);

    Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), mResources[position]);
    myView.setImageBitmap(bitmap);

    ((ViewPager) view).addView(myView);
    return myView;
}
}

At the moment I have 10 images in slideshow. When I open my Tab with Fragment described above, wait for some period, then try to go another Tab and back again to this -  I get:
    01-27 14:13:53.794 12652-12652/igor.com.totalsoulbeta E/AndroidRuntime: FATAL EXCEPTION: main
                                                                    Process: igor.com.totalsoulbeta, PID: 12652
                                                                    java.lang. OutOfMemoryError
                                                                        at android.graphics. BitmapFactory.nativeDecodeAsset(Native Method)
                                                                        at android.graphics. BitmapFactory.decodeStream(BitmapFactory.java:587)
                                                                        at android.graphics. BitmapFactory.decodeResourceStream(BitmapFactory.java:422)
                                                                        at android.graphics.drawable. Drawable.createFromResourceStream(Drawable.java:840)
                                                                        at android.content.res. Resources.loadDrawable(Resources.java:2113)
                                                                        at android.content.res. Resources.getDrawable(Resources.java:700)
                                                                        at android.content.res. XResources.getDrawable(XResources.java:521)
                                                                        at android.support.v4.content. ContextCompat.getDrawable(ContextCompat.java:323)
                                                                        at android.support.v7.widget. TintManager.getDrawable(TintManager.java:175)
                                                                        at android.support.v7.widget. TintManager.getDrawable(TintManager.java:168)
                                                                        at android.support.v7.widget. AppCompatImageHelper.setImageResource(AppCompatImageHelper.java:51)
                                                                        at android.support.v7.widget. AppCompatImageView.setImageResource(AppCompatImageView.java:72)
                                                                        at igor.com.totalsoulbeta. CustomPagerAdapter.instantiateItem(CustomPagerAdapter.java:46)

The size of each image is not more that 150kb.  My  question is: Is it possible to perfome such animation with 25 images without OutOfMemoryError?  If  yes, what I need to change in my code?  How I can clear heap and where I need  to do that? 
If it's no the best way of animating, please, advise me your variant
Thanks in advance! 

A:

A ViewPager should be able to show any number of pages.  At any time it only has 3 pages in memory (unless you change the offscreen page limit).  The probleme may lie with the Timer leaking something.  The documentation says :

When a timer is no longer needed, users should call cancel(), which
  releases the timer's thread and other resources.  Timers not explicitly
  cancelled may hold resources indefinitely. 

Does it help if you add something like that in the Fragment ? : 
@Override
public void onDestroyView() {
    super.onDestroyView();

    swipeTimer.cancel();
    swipeTimer = null;
}

