private int computeIgnoredBitmapRetainedSize(Snapshot snapshot,Instance leakingInstance){
  int bitmapRetainedSize=0;
  ClassObj bitmapClass=snapshot.findClass("android.graphics.Bitmap");
  for (  Instance bitmapInstance : bitmapClass.getInstancesList()) {
    if (isIgnoredDominator(leakingInstance,bitmapInstance)) {
      ArrayInstance mBufferInstance=fieldValue(classInstanceValues(bitmapInstance),"mBuffer");
      if (mBufferInstance == null) {
        continue;
      }
      long bufferSize=mBufferInstance.getTotalRetainedSize();
      long bitmapSize=bitmapInstance.getTotalRetainedSize();
      if (bitmapSize < bufferSize) {
        bitmapSize+=bufferSize;
      }
      bitmapRetainedSize+=bitmapSize;
    }
  }
  return bitmapRetainedSize;
}

private int computeIgnoredBitmapRetainedSize ( Snapshot snapshot , Instance leakingInstance ) { int bitmapRetainedSize = 0 ; ClassObj bitmapClass = snapshot . findClass ( "android.graphics.Bitmap" ) ; for ( Instance bitmapInstance : bitmapClass . getInstancesList ( ) ) { if ( isIgnoredDominator ( leakingInstance , bitmapInstance ) ) { ArrayInstance mBufferInstance = fieldValue ( classInstanceValues ( bitmapInstance ) , "mBuffer" ) ; if ( mBufferInstance == null ) { continue ; } long bufferSize = mBufferInstance . getTotalRetainedSize ( ) ; long bitmapSize = bitmapInstance . getTotalRetainedSize ( ) ; if ( bitmapSize < bufferSize ) { bitmapSize += bufferSize ; } bitmapRetainedSize += bitmapSize ; } } return bitmapRetainedSize ; }
bitmaps and bitmap byte arrays are sometimes held by native gc roots , so they aren ' t included in the retained size because their root dominator is a native gc root . to fix this , we check if the leaking instance is a dominator for each bitmap instance and then add the bitmap size . from experience , we ' ve found that bitmap created in code ( bitmap . createbitmap ( ) ) are correctly accounted for , however bitmaps set in layouts are not .
