I have a "memory leak" in my adapter (quotes will be explained later). I am currently using nested fragments to host a viewpager.
My setup is this:
1. Action (Empty action in which fragment A is located)
2. Fragment A - the fragment in which the viewpager with the Fragmentstatepageradapter is placed. Each page of the viewpager has a fragment B.
3. Fragment B - a fragment containing an image.
Everything works fine, except when a configuration change occurs. Watching a bunch, it seems to grow by 100 kb every time a turn occurs. In manual mode, GCing does not free memory.
Things I tried:
1. Replace fragment B with an empty fragment - the same problem occurs, so this is not the image that causes the problem.
2. Remove both pieces A and B and rotate the action. There is no memory leak, so this is not activity.
3. Used MAT before changing any orientation and after turning about 50 times to get a bunch. MAT shows 1 main suspect, which is my adapter class. It shows 7 MB of the stored heap (a very small small heap) of observers, like this:
array java.util.ArrayList @ 0x42079938 24 7,000,832 .\mObservers android.database.DataSetObservable @ 0x42053508 16 7,000,848 ..\mObservable com.example.main.Adapter@ 0x4205a048 40 7,001,416
Why am I using viewpager inside fragment:
1. I want to save the state of the adapter and other variables associated with the live viewer by setting setretaininstance (true).
2. After changing the configuration, I do not recreate the adapter, but use the old one to connect to the viewpager.
3. If I do not reuse the old adapter, but create a new adapter after changing the configuration, the memory leak will disappear.
4. The memory leak also disappears after closing the activity and returning to the previous action.
Any ideas? Would thank for any help.
Thanks JC
android memory-leaks android-viewpager fragmentstatepageradapter
JC.
source share