Bitmap memory leak in android
<p>I am working in an android application in which I am having a Bitmap and I am binding that bitmaps to an image view. I also want to set an image border and I have to set my image view in an particular angle which is my requirement. This is the code that I am using to implement this and it works fine except there will be some memory issue. How can I customize my code to avoid this memory leaks.Please have a look at the code.</p>

<p>This is my code </p>

<pre><code>String image = getIntent().getExtras().getString("image");
// Convert string to bitmap
CAPTURE_IMAGE = StringToBitMap(image);
// Set the border width
final int BORDER_WIDTH = 5;
// Set the border color
final int BORDER_COLOR = Color.WHITE;
Bitmap res = Bitmap.createBitmap(CAPTURE_IMAGE.getWidth() + 2 * BORDER_WIDTH, CAPTURE_IMAGE.getHeight() + 2 * BORDER_WIDTH, CAPTURE_IMAGE.getConfig());
Canvas c = new Canvas(res);
Paint p = new Paint();
p.setColor(BORDER_COLOR);
c.drawRect(0, 0, res.getWidth(), res.getHeight(), p);
p = new Paint(Paint.FILTER_BITMAP_FLAG);
c.drawBitmap(CAPTURE_IMAGE, BORDER_WIDTH, BORDER_WIDTH, p);
Matrix mat = new Matrix();
// Set the Imageview position
mat.postRotate(355);
setActivity(this);
bMapRotate = Bitmap.createBitmap(res, 0, 0, res.getWidth(), res.getHeight(), mat, true);

// Set the captured bitmap image in the imageview
mShareImageView.setImageBitmap(CAPTURE_IMAGE);
res.recycle();
res=null;
image=null;
p=null;
c=null;
</code></pre>
