Context and Memory leaks
<p>In my application I have a thread and a corresponding handler to update the UI. This thread will be started from my main activity, and the Thread takes several parameters, including a context. This context is used this way:</p>

<pre><code>Context c;
MessageHandler handler;

public BluetoothCommunicator(Context c) {
   this.c = c;
   handler = new MessageHandler(c);
}
</code></pre>

<p>In my <code>run()</code> method I post some data to this handler, when a special event has occured. In my <code>handleMessage()</code> method I create some ProgressDialogs, in order to inform the user that a operation is ongoing. </p>

<pre><code>@Override
    public void handleMessage(Message m) {

        String message = (String) m.obj;

        //Getting files
        if (message.equals("0")) {

            folder.appendToLogFile(new Date().toString(), "Incoming File From: " + deviceName); 

            pd = new ProgressDialog(c);
            pd.setTitle("Please Wait..");
            pd.setMessage("Retrieving file from " + deviceName);
            pd.setCancelable(false);

            pd.show();
        }
</code></pre>

<p>As I understand I cannot create a ProgressDialog with <code>getApplicationContext()</code>, but I need the <code>Activity Context</code>. </p>

<p>The way I coded this will cause a memory leak in my applicaion, according to <a href="http://www.eclipse.org/mat/" rel="nofollow">MAT</a></p>

<p><img src="http://i.stack.imgur.com/OgVVd.png" alt="enter image description here"></p>

<p>The way I see this trace is that the <code>c</code> corresponds the the object <code>c</code> I initalize in my constructor. Is this right?</p>

<p>How can I go around this problem? No an AsyncTask is not relevant because the problem is in the <code>Context</code>. </p>
