Android : References to a Context and memory leaks

Viewed 18366

I've read that it is a mistake and a source of memory leaks in Android application to keep a long-lived references to a Context.

But I don't understand if it is ok to create a class that looks like this one:

public class HelperClass {
    private Context context;

    public HelperClass(Context context) {
        this.context = context;
    }
    public void myHelperMethod() {
        // uses this.context
    }
}

And call it from an Activity:

public class MyActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        HelperClass h = new HelperClass(this);
        h.myHelperMethod();
    }

    ...
}
2 Answers
Related