MichelReap
MichelReap

Reputation: 5770

ViewPager with FragmentPagerAdapter OutOfMemory

I have a viewpager with multiple types of pages (images, videos), so I used FragmentPagerAdapter.

The problem now is, when I have around 14 pages (mostly images) I get an outofmemory error when sliding to the latter ones. I can see a memory leak when changing pages since memory usage only increases and never goes down.

I tried reimplementing the onDEstroyItem method as suggested in other posts, but this seems to work with views instead of Fragments.

What should I do?

Upvotes: 1

Views: 3550

Answers (1)

Yaroslav Mytkalyk
Yaroslav Mytkalyk

Reputation: 17105

You should use FragmentStatePagerAdapter instead of FragmentPagerAdapter as mentioned here. Also try to decrease the value set by setOffscreenPageLimit as mentioned.

Upvotes: 5

Related Questions