WeakReference with ImageView?
<p>I'm not too familiar with WeakReference, wanted to see if my use of them is correct. Here's the skeleton of an image fetcher:</p>

<pre><code>class Request {
    String url;
    WeakReference&lt;ImageView&gt; view;

    public Request(String url, ImageView iv) {
        this.url = url;
        this.view = new WeakReference(iv);
    }
}

class Fetcher {

    private static List&lt;Request&gt; requests;

    public static void addRequest(String url, ImageView iv) {
        mRequests.add(new Request(url, iv));
    }
}
</code></pre>

<p>So now the static, global list "requests" has weak references to ImageViews from different contexts / activities. If I understand correctly, this won't be a garbage collection problem - if an activity gets destroyed, the "requests" array will let the ImageViews from that activity get garbage collected ok, right? I'd just find my references are null:</p>

<pre><code>public static void fetchForRequest(Request request) {
    Bitmap bmp = foo(url);
    if (request.view.get() != null) {
        // Still good!
        request.view.get().setBitmap(bmp);
    } else {
        // Our reference is gone!
    }
}
</code></pre>

<p>The above ignores all synchronization issues etc, just wanted to check if I'm understanding WeakReference correctly. I'd hate to get an outofmemory exception because I have hard references to 100s of ImageViews!</p>

<p>Thanks</p>
