リフレクトでドローアブルを作成しようとしています。これが私のコードです:
public Drawable createReflectedImage(Drawable d) {
int width = d.getIntrinsicWidth();
int height = d.getIntrinsicHeight();
Bitmap originalImage = Bitmap.createBitmap(width, height,
Config.ARGB_8888);
d.setBounds(0, 0, width, height);
Canvas canvas = new Canvas(originalImage);
d.draw(canvas);
final int reflectionGap = 4;
Matrix matrix = new Matrix();
matrix.preScale(1, -1);
Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0,
height / 2, width, height / 2, matrix, false);
Bitmap bitmapWithReflection = Bitmap.createBitmap(width,
(height + height / 2), Config.ARGB_8888);
canvas = new Canvas(bitmapWithReflection);
canvas.drawBitmap(originalImage, 0, 0, null);
Paint deafaultPaint = new Paint();
canvas.drawRect(0, height, width, height + reflectionGap, deafaultPaint);
canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);
Paint paint = new Paint();
LinearGradient shader = new LinearGradient(0,
originalImage.getHeight(), 0, bitmapWithReflection.getHeight()
+ reflectionGap, 0x70ffffff, 0x00ffffff,
TileMode.MIRROR);
paint.setShader(shader);
paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
canvas.drawRect(0, height, width, bitmapWithReflection.getHeight()
+ reflectionGap, paint);
BitmapDrawable drawable = new BitmapDrawable(getContext()
.getResources(), bitmapWithReflection);
originalImage.recycle();
reflectionImage.recycle();
return drawable;
}
createReflectedImage
この関数の最後に null を返すだけでも、呼び出されるたびに次のログが表示されました。
10-29 10:56:48.541: I/dalvikvm-heap(23989): Grow heap (frag case) to 19.332MB for 960016-byte allocation
このメモリリークがどのように発生したかを理解してくれる人はいますか?