{"action":"created","issue":{"url":"https://api.github.com/repos/siyamed/android-shape-imageview/issues/17","labels_url":"https://api.github.com/repos/siyamed/android-shape-imageview/issues/17/labels{/name}","comments_url":"https://api.github.com/repos/siyamed/android-shape-imageview/issues/17/comments","events_url":"https://api.github.com/repos/siyamed/android-shape-imageview/issues/17/events","html_url":"https://github.com/siyamed/android-shape-imageview/issues/17","id":57587961,"number":17,"title":"Posible memory leak issue","user":{"login":"r1m","id":10991794,"avatar_url":"https://avatars.githubusercontent.com/u/10991794?v=3","gravatar_id":"","url":"https://api.github.com/users/r1m","html_url":"https://github.com/r1m","followers_url":"https://api.github.com/users/r1m/followers","following_url":"https://api.github.com/users/r1m/following{/other_user}","gists_url":"https://api.github.com/users/r1m/gists{/gist_id}","starred_url":"https://api.github.com/users/r1m/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/r1m/subscriptions","organizations_url":"https://api.github.com/users/r1m/orgs","repos_url":"https://api.github.com/users/r1m/repos","events_url":"https://api.github.com/users/r1m/events{/privacy}","received_events_url":"https://api.github.com/users/r1m/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"siyamed","id":1331331,"avatar_url":"https://avatars.githubusercontent.com/u/1331331?v=3","gravatar_id":"","url":"https://api.github.com/users/siyamed","html_url":"https://github.com/siyamed","followers_url":"https://api.github.com/users/siyamed/followers","following_url":"https://api.github.com/users/siyamed/following{/other_user}","gists_url":"https://api.github.com/users/siyamed/gists{/gist_id}","starred_url":"https://api.github.com/users/siyamed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/siyamed/subscriptions","organizations_url":"https://api.github.com/users/siyamed/orgs","repos_url":"https://api.github.com/users/siyamed/repos","events_url":"https://api.github.com/users/siyamed/events{/privacy}","received_events_url":"https://api.github.com/users/siyamed/received_events","type":"User","site_admin":false},"milestone":null,"comments":3,"created_at":"2015-02-13T11:25:07Z","updated_at":"2015-11-10T14:31:50Z","closed_at":null,"body":"Hello,\r\n\r\nFirst of all great library, thank you. I think you have a memory leak in your code that is causing OutOfMemory errors. I have added these lines of code in the PorterImageView class and they are gone now. I'm not really sure if they are all needed.\r\n\r\n```java\r\n    @Override\r\n    protected void onDetachedFromWindow()\r\n    {\r\n        super.onDetachedFromWindow();\r\n        if (maskBitmap != null && !maskBitmap.isRecycled()) maskBitmap.recycle();\r\n        if (drawableBitmap != null && !drawableBitmap.isRecycled()) drawableBitmap.recycle();\r\n    }\r\n```\r\n```java\r\n private void createMaskCanvas(int width, int height, int oldw, int oldh)\r\n    {\r\n            ...\r\n            Bitmap oldBitmap = maskBitmap;\r\n            maskBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);\r\n            if (oldBitmap != null && oldBitmap != maskBitmap && !oldBitmap.isRecycled()) oldBitmap.recycle();\r\n            maskCanvas.setBitmap(maskBitmap);\r\n\r\n            ...\r\n\r\n            oldBitmap = drawableBitmap;\r\n            drawableBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);\r\n            if (oldBitmap != null && oldBitmap != drawableBitmap && !oldBitmap.isRecycled()) oldBitmap.recycle();\r\n            drawableCanvas.setBitmap(drawableBitmap);\r\n            ...\r\n        }\r\n    }\r\n```"},"comment":{"url":"https://api.github.com/repos/siyamed/android-shape-imageview/issues/comments/155435555","html_url":"https://github.com/siyamed/android-shape-imageview/issues/17#issuecomment-155435555","issue_url":"https://api.github.com/repos/siyamed/android-shape-imageview/issues/17","id":155435555,"user":{"login":"alfdev","id":156018,"avatar_url":"https://avatars.githubusercontent.com/u/156018?v=3","gravatar_id":"","url":"https://api.github.com/users/alfdev","html_url":"https://github.com/alfdev","followers_url":"https://api.github.com/users/alfdev/followers","following_url":"https://api.github.com/users/alfdev/following{/other_user}","gists_url":"https://api.github.com/users/alfdev/gists{/gist_id}","starred_url":"https://api.github.com/users/alfdev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alfdev/subscriptions","organizations_url":"https://api.github.com/users/alfdev/orgs","repos_url":"https://api.github.com/users/alfdev/repos","events_url":"https://api.github.com/users/alfdev/events{/privacy}","received_events_url":"https://api.github.com/users/alfdev/received_events","type":"User","site_admin":false},"created_at":"2015-11-10T14:31:50Z","updated_at":"2015-11-10T14:31:50Z","body":"I applies this changes:\r\n    private void createMaskCanvas(int width, int height, int oldw, int oldh) {\r\n        boolean sizeChanged = width != oldw || height != oldh;\r\n        boolean isValid = width > 0 && height > 0;\r\n        if(isValid && (maskCanvas == null || sizeChanged)) {\r\n            maskCanvas = new Canvas();\r\n            Bitmap oldBitmap = maskBitmap;\r\n            maskBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);\r\n            if (oldBitmap != null && oldBitmap != maskBitmap && !oldBitmap.isRecycled()) oldBitmap.recycle();\r\n            maskCanvas.setBitmap(maskBitmap);\r\n\r\n            maskPaint.reset();\r\n            paintMaskCanvas(maskCanvas, maskPaint, width, height);\r\n\r\n            drawableCanvas = new Canvas();\r\n            oldBitmap = drawableBitmap;\r\n            drawableBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);\r\n            if (oldBitmap != null && oldBitmap != drawableBitmap && !oldBitmap.isRecycled()) oldBitmap.recycle();\r\n            drawableCanvas.setBitmap(drawableBitmap);\r\n            drawablePaint = new Paint(Paint.ANTI_ALIAS_FLAG);\r\n            invalidated = true;\r\n        }\r\n    }\r\n\r\nAnd this:\r\n\r\n    @Override\r\n    protected void onDetachedFromWindow() {\r\n        super.onDetachedFromWindow();\r\n\r\n        if (maskBitmap != null && !maskBitmap.isRecycled()) maskBitmap.recycle();\r\n        if (drawableBitmap != null && !drawableBitmap.isRecycled()) drawableBitmap.recycle();\r\n    }"}}