I built an Android application which has a ViewPager with 6 pages. For every page a have a small image which I use (not background, just for an ImageView).
These images are about 130KB each. I noticed that when this activity starts I get messages like this one:
02-09 21:23:58.755: I/dalvikvm-heap(6478): Grow heap (frag case) to 49.015MB for 2457616-byte allocation
After playing a while, I also get an OOM exception.
I do not understand why an image of such size takes to much space when it is loaded.
Has anyone faced such a problem? Any solution?
Thanks in advance!
[UPDATE]
Apologies for not adding code :)
Below is the onCreateView of the Fragment I use in the ViewPager:
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ViewGroup rootView = (ViewGroup) inflater.inflate( R.layout.fragment_selection, container, false); mSelectionImage = (ImageView) rootView .findViewById(R.id.selection_image); switch (mPageNumber) { case 0: mSelectionImage.setImageResource(R.drawable.img_sel_0); break; case 1: mSelectionImage .setImageResource(R.drawable.img_sel_1); break; case 2: mSelectionImage.setImageResource(R.drawable.img_sel_2); break; case 3: mSelectionImage .setImageResource(R.drawable.img_sel_3); break; case 4: mSelectionImage.setImageResource(R.drawable.img_sel_4); break; case 5: mSelectionImage .setImageResource(R.drawable.img_sel_5); break; default: break; } return rootView; }