{"action":"created","issue":{"url":"https://api.github.com/repos/bumptech/glide/issues/1002","repository_url":"https://api.github.com/repos/bumptech/glide","labels_url":"https://api.github.com/repos/bumptech/glide/issues/1002/labels{/name}","comments_url":"https://api.github.com/repos/bumptech/glide/issues/1002/comments","events_url":"https://api.github.com/repos/bumptech/glide/issues/1002/events","html_url":"https://github.com/bumptech/glide/issues/1002","id":136382673,"number":1002,"title":"OutOfMemoryError thrown after loading tons of pictures in RecyclerView","user":{"login":"imlunacat","id":2828387,"avatar_url":"https://avatars.githubusercontent.com/u/2828387?v=3","gravatar_id":"","url":"https://api.github.com/users/imlunacat","html_url":"https://github.com/imlunacat","followers_url":"https://api.github.com/users/imlunacat/followers","following_url":"https://api.github.com/users/imlunacat/following{/other_user}","gists_url":"https://api.github.com/users/imlunacat/gists{/gist_id}","starred_url":"https://api.github.com/users/imlunacat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/imlunacat/subscriptions","organizations_url":"https://api.github.com/users/imlunacat/orgs","repos_url":"https://api.github.com/users/imlunacat/repos","events_url":"https://api.github.com/users/imlunacat/events{/privacy}","received_events_url":"https://api.github.com/users/imlunacat/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/bumptech/glide/labels/question","name":"question","color":"d4c5f9"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2016-02-25T13:05:00Z","updated_at":"2016-03-04T09:29:56Z","closed_at":null,"body":"Hello,\r\n  I tried use Glide to display internet picture inside RecyclerView. After lot of picture is loaded into RecyclerView. PriorityExecutor throws OutOfMemoryError and following picture cannot be loaded ;(\r\n\r\n  Here is snippet of inside ViewHolder's bindView:\r\n```java\r\n Glide.with(itemView.getContext())\r\n    .load(url)\r\n    .listener(sRequestListener) // sRequestListener is a simple logger\r\n    .placeholder(placeHolder)\r\n    .error(placeHolder)\r\n    .into(new CustomViewTarget(itemView.imageview));\r\n    // CustomViewTarget is an implementation of ImageViewTarget to help set/get Request\r\n```\r\n\r\n  ViewHolder:\r\n```xml\r\n<RelativeLayout\r\n      ....>\r\n      <SquareImageView\r\n        android:id=\"@+id/imageview\"\r\n        android:layout_width=\"match_parent\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:scaleType=\"fitCenter\"\r\n        android:src=\"@drawable/bg_default\" />\r\n    <TextView ....\r\n   ....\r\n</RelativeLayout>\r\n```\r\n  Implementation of CustomViewTarget\r\n```java\r\n// extends com.bumptech.glide.request.target.ImageViewTarget\r\npublic class CustomViewTarget extends ImageViewTarget<GlideDrawable> {\r\n    private static final int GLIDE_REQUEST_TAG_ID = -1;\r\n    public NYImageViewTarget(ImageView view) {\r\n        super(view);\r\n    }\r\n\r\n    @Override\r\n    protected void setResource(GlideDrawable resource) {\r\n        view.setImageDrawable(resource);\r\n    }\r\n\r\n    @Override\r\n    public void setRequest(Request request) {\r\n        view.setTag(GLIDE_REQUEST_TAG_ID, request);\r\n    }\r\n\r\n    @Override\r\n    public Request getRequest(){\r\n        Object tag = view.getTag(GLIDE_REQUEST_TAG_ID);\r\n        if (tag != null) {\r\n            if (tag instanceof Request) {\r\n                return (Request) tag;\r\n            } else {\r\n                throw new IllegalArgumentException(\"tag is not instance of Request\");\r\n            }\r\n        }\r\n\r\n        return null;\r\n    }\r\n}\r\n```\r\n  SquareImageView is child of ImageView. It overrides onMeasure of ImageView\r\n```java\r\n    @Override\r\n    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {\r\n        float padding = (float) (getPaddingLeft() + getPaddingRight());\r\n        int widthSize = Math.round(MeasureSpec.getSize(widthMeasureSpec) - padding);\r\n        setMeasuredDimension(widthSize, widthSize);\r\n    }\r\n```\r\n\r\nsRequestListener is a simple logger, log would be remove in release.\r\n```java\r\npublic class CustomRequestListener<T, R> implements RequestListener<T, R> {\r\n    private static final String TAG = CustomRequestListener.class.getSimpleName();\r\n    public CustomRequestListener(){\r\n    }\r\n    @Override\r\n    public boolean onException(Exception e, T model, Target<R> target, boolean isFirstResource) {\r\n        Log.d(TAG, String.format(Locale.ROOT, \"onException(%s, %s, %s, %s)\", e, model, target, isFirstResource), e);\r\n        return false;\r\n    }\r\n\r\n    @Override\r\n    public boolean onResourceReady(R resource, T model, Target<R> target, boolean isFromMemoryCache,\r\n            boolean isFirstResource) {\r\n        Log.d(TAG, String.format(Locale.ROOT,\r\n                \"onResourceReady(%s, %s, %s, %s, %s)\", resource, model, target, isFromMemoryCache, isFirstResource));\r\n        return false;\r\n    }\r\n}\r\n```\r\n  Glide version: 3.7.0 \r\n\r\n  Sorry for the long text of code ;( \r\n\r\n  Is it possible to avoid this situation? Thank you."},"comment":{"url":"https://api.github.com/repos/bumptech/glide/issues/comments/192204660","html_url":"https://github.com/bumptech/glide/issues/1002#issuecomment-192204660","issue_url":"https://api.github.com/repos/bumptech/glide/issues/1002","id":192204660,"user":{"login":"peterbetos","id":3241327,"avatar_url":"https://avatars.githubusercontent.com/u/3241327?v=3","gravatar_id":"","url":"https://api.github.com/users/peterbetos","html_url":"https://github.com/peterbetos","followers_url":"https://api.github.com/users/peterbetos/followers","following_url":"https://api.github.com/users/peterbetos/following{/other_user}","gists_url":"https://api.github.com/users/peterbetos/gists{/gist_id}","starred_url":"https://api.github.com/users/peterbetos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterbetos/subscriptions","organizations_url":"https://api.github.com/users/peterbetos/orgs","repos_url":"https://api.github.com/users/peterbetos/repos","events_url":"https://api.github.com/users/peterbetos/events{/privacy}","received_events_url":"https://api.github.com/users/peterbetos/received_events","type":"User","site_admin":false},"created_at":"2016-03-04T09:29:56Z","updated_at":"2016-03-04T09:29:56Z","body":"This is still happening when I download tons of images having 800 x 400 pixel dimensions"}}