How to keep a Bitmap in memory
<p>Following up on <a href="http://stackoverflow.com/questions/8814455/storing-a-bitmap-resource-in-a-static-variable">Storing a Bitmap resource in a static variable</a>, it seems that storing a static reference to an <code>android.graphics.Bitmap</code> in a <code>View</code> may leak a reference to that first <code>View</code> that instantiated it. What's the idiomatic way to solve this in Android? I do not want to call <code>BitmapFactory.decodeResource(resource, id)</code> each time an instance of this view is instantiated because this will be done (many times) in every single Activity. I want this small <code>Bitmap</code> to always remain in memory. So, what is the correct way to do the following:</p>

<pre><code>public class MyView extends View {
    private static Bitmap star;
    public MyView(Context context) {
        synchronized(this) {
            if (star == null) {
                star = BitmapFactory.decodeResource(getResources(), R.drawable.star);
            }
        }
    }
    // ...
}
</code></pre>
