question: @ VisibleForTesting synchronized void trimToSize ( int targetSize ) { int bytesToFree = Math . min ( mUsed . mNumBytes + mFree . mNumBytes - targetSize , mFree . mNumBytes ) ; if ( bytesToFree <= 0 ) { return ; } if ( FLog . isLoggable ( FLog . VERBOSE ) ) { FLog . v ( TAG , "trimToSize: TargetSize = %d; Initial Size = %d; Bytes to free = %d" , targetSize , mUsed . mNumBytes + mFree . mNumBytes , bytesToFree ) ; } logStats ( ) ; for ( int i = 0 ; i < mBuckets . size ( ) ; ++ i ) { if ( bytesToFree <= 0 ) { break ; } Bucket < V > bucket = mBuckets . valueAt ( i ) ; while ( bytesToFree > 0 ) { V value = bucket . pop ( ) ; if ( value == null ) { break ; } free ( value ) ; bytesToFree -= bucket . mItemSize ; mFree . decrement ( bucket . mItemSize ) ; } } logStats ( ) ; if ( FLog . isLoggable ( FLog . VERBOSE ) ) { FLog . v ( TAG , "trimToSize: TargetSize = %d; Final Size = %d" , targetSize , mUsed . mNumBytes + mFree . mNumBytes ) ; } }
target:  (Try to) trim the pool until its total space falls below the max size (soft cap). This will get rid of values on the free list, until the free lists are empty, or we fall below the max size; whichever comes first. NOTE: It is NOT an error if we have eliminated all the free values, but the pool is still above its max size (soft cap) <p> The approach we take is to go from the smallest sized bucket down to the largest sized bucket. This may seem a bit counter-intuitive, but the rationale is that allocating larger-sized values is more expensive than the smaller-sized ones, so we want to keep them around for a while.