2

I have an activity that hosts a fragment with Gallery inside it. When I start another activity , essentially, I want to free the memory filled with gallery bitmaps.

My fragment is inserted dynamically like this:

FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager
            .beginTransaction();

    if (_promoFragment == null) {
        _promoFragment = new TabletPromoFragment();
    }

    fragmentTransaction.replace(_singlePageContainerId, _promoFragment);

    fragmentTransaction.commit();

I even call _promoFragment.onDestroyView in onPause of the activity, but MAT still shows me that there's a Gallery object that holds those references to Bitmaps.

What can you suggest ?

p.s. I can post MAT report if it is more clear.

midnight
  • 3,420
  • 3
  • 36
  • 58

2 Answers2

1

You are having problems with references and objects clinging on to memory way past the lifecycle of your fragments & activities.

Check out my reply on this post

You have to ensure no reference is left behind whenever you destroy a fragment/activity. Make sure to clear all its usage and history so Android's Garbage Collector successfully processes it

Community
  • 1
  • 1
Ricardo Vieira
  • 1,738
  • 1
  • 18
  • 26
0

Use weak references for Bitmaps. http://developer.android.com/reference/java/lang/ref/WeakReference.html

Mus
  • 1,860
  • 2
  • 16
  • 19
  • I've already used - I'm using https://github.com/thest1/LazyList/blob/master/src/com/fedorvlasov/lazylist/ImageLoader.java to show bitmaps acyncroniously. I have a doubt about this line: private Map cache=Collections.synchronizedMap( new LinkedHashMap(10,1.5f,true)); However I think my problem is that fragments view doesn;t get destryed when I leave the first activity – midnight Aug 22 '12 at 11:40