@Override protected void onDestroy() { super.onDestroy(); if (mCurrentBitmapReference != null && mCurrentBitmapReference.isValid()) { mCurrentBitmapReference.close(); } }
@Test public void testGet_Realloc() { CloseableReference<byte[]> arrayRef = mArray.get(1); final byte[] smallArray = arrayRef.get(); arrayRef.close(); arrayRef = mArray.get(7); assertEquals(8, arrayRef.get().length); assertSame(mArray.mByteArraySoftRef.get(), arrayRef.get()); assertNotSame(smallArray, arrayRef.get()); }
public void setImageBitmap(CloseableReference<Bitmap> bitmapReference) { // Note: This is not a recommended way to load Bitmap. // This sample is intended to test the internal methods, and show how to use them. Bitmap bitmap = bitmapReference.get(); mImageView.setImageBitmap(bitmap); mImageView.getLayoutParams().width = (int) (bitmap.getWidth() * mConversionFactor); mImageView.getLayoutParams().height = (int) (bitmap.getHeight() * mConversionFactor); if (mCurrentBitmapReference != null && mCurrentBitmapReference.isValid()) { mCurrentBitmapReference.close(); } mCurrentBitmapReference = bitmapReference; }