I have a fragment that hosts a ViewPager populated by the FragmentStatePager adapter. Children's fragment consists of a square. ImageView is the width of the phone screen, and TextView is the username. The purpose of this snippet is to allow scrolling through a series of images similar to the gallery app, and all photos are uploaded by the Picasso Library.
None of these fragments have private View variables, and both have onDestroy and onDetach called after you pull out the backstack on which they are included. However, after using the Eclispe MAT, these fragments still retain memory, and I have no idea why.
PhotoParentFragment fields consist only of them:
public class PhotoParentFragment extends BaseFragment implements ViewPager.OnPageChangeListener, Observer<Integer> { public static final String TAG = PhotoParentFragment.class.getSimpleName(); private static final String PHOTO_LIST = "PHOTO_LIST"; private static final String CURRENT_PHOTO = "CURRENT_PHOTO"; private boolean isBucketListMenuAdded = false; private static final int DELETE = 4; private static final int ERROR = 5; private int currentPhoto = 0; private ArrayList<Photo> photos; public static PhotoParentFragment newInstance(int sectionNumber, int currentPhoto, ArrayList<Photo> photos) { PhotoParentFragment fragment = new PhotoParentFragment(); Bundle args = new Bundle(); args.putInt(Utils.ARG_SECTION_NUMBER, sectionNumber); args.putInt(CURRENT_PHOTO, currentPhoto); args.putParcelableArrayList(PHOTO_LIST, photos); fragment.setArguments(args); return fragment; }
The fields of the PhotoChild fragment consist only of them:
public class PhotoChildFragment extends BaseFragment implements View.OnClickListener { public static final String TAG = PhotoChildFragment.class.getSimpleName(); private static final String NUM_PHOTOS = "NUM_PHOTOS"; private static final String PHOTO = "PHOTO"; private int imageSize; private int position; private int numOfPhotos; private Photo photo; private boolean isPhotoOwner = false; public static PhotoChildFragment newInstance(int position, int numPhotos, Photo photo) { PhotoChildFragment fragment = new PhotoChildFragment(); Bundle args = new Bundle(); args.putInt(Utils.ARG_SECTION_NUMBER, position); args.putInt(NUM_PHOTOS, numPhotos); args.putParcelable(PHOTO, photo); fragment.setArguments(args); return fragment; }
In the onCreateView for the parent, I configure my ViewPager as follows:
final PhotoPagerAdapter photoPagerAdapter = new PhotoPagerAdapter(getChildFragmentManager(), photos.size()); final ViewPager viewPager = (ViewPager) rootView.findViewById(R.id.pager); photoPagerAdapter.setPhotos(photos); viewPager.addOnPageChangeListener(this); viewPager.setAdapter(photoPagerAdapter); viewPager.setCurrentItem(currentPhoto);
No static links exist. Now, when I pop a fragment from the back stack, despite the fact that onDetach and onDestroy are called for all fragments, both parent and several children, the fragments are still saved. A call to getSupportFragmentManager.getFragments.size () also indicates that the parent fragment is missing.
However, MAT says otherwise. The screenshot I am showing is the result of clicking on a photo from the list and clicking 4 times:
Ignore profilePhotoAdapter $ ViewHolder and UserListAdapter $ ViewHolder. They are from different things.

Please note that 4 parent fragments are saved and 12 child fragments (4 * 3) are saved. It really drives me crazy. Merging shortest paths with GC roots gives this, which is not entirely useful:

So, please, if someone experienced this, please, how did you fix it?
Finally, both parents and Child have setOptionsMenu in true.