<p dir="auto">Hello. I found a memory leak in <strong>com.bumptech.glide.request.target.ViewTarget</strong>.</p>
<p dir="auto"><strong>GlideDrawableImageViewTarget</strong> provide a memory leak. It keeps a reference to my activity. And GC can not release the activity.</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/2863246/13455487/59200878-e066-11e5-9ea9-f145a9f6506a.png"><img src="https://cloud.githubusercontent.com/assets/2863246/13455487/59200878-e066-11e5-9ea9-f145a9f6506a.png" alt="2016-02-24_17-33-43" style="max-width: 100%;"></a></p>
<p dir="auto">I found this problem when run "SELECT * FROM instanceof android.support.v7.app.AppCompatActivity" in MAT.</p>
<p dir="auto">When I use<br>
<code class="notranslate">protected final WeakReference&lt;T&gt; view;</code><br>
in  <strong>com.bumptech.glide.request.target.ViewTarget</strong> I resolved this problem for me.</p>
<p dir="auto">P.S. Sorry for my English :)</p>
<p dir="auto"><strong>Glide Version</strong>: com.github.bumptech.glide:glide:3.7.0<br>
<strong>Integration libraries</strong>:</p>
<div class="highlight highlight-source-groovy-gradle notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta1'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'com.github.bumptech.glide:okhttp-integration:1.3.1@aar'
    compile 'com.google.code.gson:gson:2.6.2'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.squareup.okhttp:okhttp:2.5.0'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.5.0'
    compile 'com.android.support:recyclerview-v7:23.1.1'
    compile 'com.android.support:cardview-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'"><pre class="notranslate">    debugCompile <span class="pl-s"><span class="pl-pds">'</span>com.squareup.leakcanary:leakcanary-android:1.4-beta1<span class="pl-pds">'</span></span>
    compile fileTree(<span class="pl-c1">dir</span>: <span class="pl-s"><span class="pl-pds">'</span>libs<span class="pl-pds">'</span></span>, <span class="pl-c1">include</span>: [<span class="pl-s"><span class="pl-pds">'</span>*.jar<span class="pl-pds">'</span></span>])
    compile <span class="pl-s"><span class="pl-pds">'</span>com.android.support:appcompat-v7:23.1.1<span class="pl-pds">'</span></span>
    compile <span class="pl-s"><span class="pl-pds">'</span>com.github.bumptech.glide:glide:3.7.0<span class="pl-pds">'</span></span>
    compile <span class="pl-s"><span class="pl-pds">'</span>com.github.bumptech.glide:okhttp-integration:1.3.1@aar<span class="pl-pds">'</span></span>
    compile <span class="pl-s"><span class="pl-pds">'</span>com.google.code.gson:gson:2.6.2<span class="pl-pds">'</span></span>
    compile <span class="pl-s"><span class="pl-pds">'</span>com.squareup.retrofit:retrofit:1.9.0<span class="pl-pds">'</span></span>
    compile <span class="pl-s"><span class="pl-pds">'</span>com.squareup.okhttp:okhttp:2.5.0<span class="pl-pds">'</span></span>
    compile <span class="pl-s"><span class="pl-pds">'</span>com.squareup.okhttp:okhttp-urlconnection:2.5.0<span class="pl-pds">'</span></span>
    compile <span class="pl-s"><span class="pl-pds">'</span>com.android.support:recyclerview-v7:23.1.1<span class="pl-pds">'</span></span>
    compile <span class="pl-s"><span class="pl-pds">'</span>com.android.support:cardview-v7:23.1.1<span class="pl-pds">'</span></span>
    compile <span class="pl-s"><span class="pl-pds">'</span>com.android.support:design:23.1.1<span class="pl-pds">'</span></span></pre></div>
<p dir="auto"><strong>Device/Android Version</strong>: Android 4.1.1 tested, Genemotion<br>
<strong>Issue details / Repro steps / Use case background</strong>:</p>
<ol dir="auto">
<li>Open my app</li>
<li>Open an activity where showing RecycelerView with images</li>
<li>Then press Back -&gt; Back -&gt; .... Home Screen.</li>
<li>After I wait about 1 minute and press to run GC.</li>
<li>I have leakcanary.  I saw next memory leak.</li>
</ol>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/2863246/13631264/6c4ae8ba-e5ec-11e5-8f3d-80903f11c2ce.png"><img src="https://cloud.githubusercontent.com/assets/2863246/13631264/6c4ae8ba-e5ec-11e5-8f3d-80903f11c2ce.png" alt="image" style="max-width: 100%;"></a></p>
<ol dir="auto">
<li>Then I collected glide.hprof and saw a memory leak.<br>
<em><strong>(SELECT * FROM instanceof android.support.v7.app.AppCompatActivity)</strong></em></li>
</ol>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/2863246/13631155/cadca496-e5eb-11e5-90b2-3db41af76f3f.png"><img src="https://cloud.githubusercontent.com/assets/2863246/13631155/cadca496-e5eb-11e5-90b2-3db41af76f3f.png" alt="2016-03-09_11-40-04" style="max-width: 100%;"></a></p>
<p dir="auto"><strong>Glide load line</strong>:<br>
Next code running in RecyclerView.Adapter.</p>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Glide.with(context)
        .load(images.get(i))
        .error(android.R.drawable.ic_delete)
        .centerCrop()
        .into(viewHolder.imageViewCar);"><pre class="notranslate"><span class="pl-smi">Glide</span>.<span class="pl-en">with</span>(<span class="pl-s1">context</span>)
        .<span class="pl-en">load</span>(<span class="pl-s1">images</span>.<span class="pl-en">get</span>(<span class="pl-s1">i</span>))
        .<span class="pl-en">error</span>(<span class="pl-s1">android</span>.<span class="pl-s1">R</span>.<span class="pl-s1">drawable</span>.<span class="pl-s1">ic_delete</span>)
        .<span class="pl-en">centerCrop</span>()
        .<span class="pl-en">into</span>(<span class="pl-s1">viewHolder</span>.<span class="pl-s1">imageViewCar</span>);</pre></div>
<p dir="auto">context - GalleryFragment -&gt; original methot getContext() from android.support.v4.app.Fragment;</p>
<p dir="auto"><strong>Layout XML</strong>:</p>
<div class="highlight highlight-text-xml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;RelativeLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    xmlns:tools=&quot;http://schemas.android.com/tools&quot;
    android:layout_width=&quot;match_parent&quot;
    android:layout_height=&quot;match_parent&quot;&gt;

    &lt;android.support.v7.widget.CardView
        android:id=&quot;@+id/cardViewGalleryItem&quot;
        android:layout_width=&quot;match_parent&quot;
        android:layout_height=&quot;wrap_content&quot;&gt;

        &lt;ImageView
            android:id=&quot;@+id/imageViewCar&quot;
            android:layout_width=&quot;match_parent&quot;
            android:layout_height=&quot;150dp&quot;
            android:scaleType=&quot;centerCrop&quot;
            tools:src=&quot;@drawable/notification_template_icon_bg&quot; /&gt;
    &lt;/android.support.v7.widget.CardView&gt;
&lt;/RelativeLayout&gt;"><pre class="notranslate">&lt;?<span class="pl-ent">xml</span><span class="pl-e"> version</span>=<span class="pl-s"><span class="pl-pds">"</span>1.0<span class="pl-pds">"</span></span><span class="pl-e"> encoding</span>=<span class="pl-s"><span class="pl-pds">"</span>utf-8<span class="pl-pds">"</span></span>?&gt;
&lt;<span class="pl-ent">RelativeLayout</span> <span class="pl-e">xmlns</span><span class="pl-e">:</span><span class="pl-e">android</span>=<span class="pl-s"><span class="pl-pds">"</span>http://schemas.android.com/apk/res/android<span class="pl-pds">"</span></span>
    <span class="pl-e">xmlns</span><span class="pl-e">:</span><span class="pl-e">tools</span>=<span class="pl-s"><span class="pl-pds">"</span>http://schemas.android.com/tools<span class="pl-pds">"</span></span>
    <span class="pl-e">android</span><span class="pl-e">:</span><span class="pl-e">layout_width</span>=<span class="pl-s"><span class="pl-pds">"</span>match_parent<span class="pl-pds">"</span></span>
    <span class="pl-e">android</span><span class="pl-e">:</span><span class="pl-e">layout_height</span>=<span class="pl-s"><span class="pl-pds">"</span>match_parent<span class="pl-pds">"</span></span>&gt;

    &lt;<span class="pl-ent">android</span>.support.v7.widget.CardView
        <span class="pl-e">android</span><span class="pl-e">:</span><span class="pl-e">id</span>=<span class="pl-s"><span class="pl-pds">"</span>@+id/cardViewGalleryItem<span class="pl-pds">"</span></span>
        <span class="pl-e">android</span><span class="pl-e">:</span><span class="pl-e">layout_width</span>=<span class="pl-s"><span class="pl-pds">"</span>match_parent<span class="pl-pds">"</span></span>
        <span class="pl-e">android</span><span class="pl-e">:</span><span class="pl-e">layout_height</span>=<span class="pl-s"><span class="pl-pds">"</span>wrap_content<span class="pl-pds">"</span></span>&gt;

        &lt;<span class="pl-ent">ImageView</span>
            <span class="pl-e">android</span><span class="pl-e">:</span><span class="pl-e">id</span>=<span class="pl-s"><span class="pl-pds">"</span>@+id/imageViewCar<span class="pl-pds">"</span></span>
            <span class="pl-e">android</span><span class="pl-e">:</span><span class="pl-e">layout_width</span>=<span class="pl-s"><span class="pl-pds">"</span>match_parent<span class="pl-pds">"</span></span>
            <span class="pl-e">android</span><span class="pl-e">:</span><span class="pl-e">layout_height</span>=<span class="pl-s"><span class="pl-pds">"</span>150dp<span class="pl-pds">"</span></span>
            <span class="pl-e">android</span><span class="pl-e">:</span><span class="pl-e">scaleType</span>=<span class="pl-s"><span class="pl-pds">"</span>centerCrop<span class="pl-pds">"</span></span>
            <span class="pl-e">tools</span><span class="pl-e">:</span><span class="pl-e">src</span>=<span class="pl-s"><span class="pl-pds">"</span>@drawable/notification_template_icon_bg<span class="pl-pds">"</span></span> /&gt;
    &lt;/<span class="pl-ent">android</span>.support.v7.widget.CardView&gt;
&lt;/<span class="pl-ent">RelativeLayout</span>&gt;</pre></div>
<p dir="auto"><a href="https://github.com/DenBond7/GlideViewTargetMemoryLeakProject"><strong>Link to test project</strong></a></p>