Simple Android application going OOM
<p>I have a simple application, collecting and showing Wifi scan results with a few extra features, no intense CPU/RAM usage.</p>

<p>Problem is while my Thread is running (This thread scan and outputs results via a ExpandableListView), my memory is being filled up avg 70Mb at a time.</p>

<p>I noticed when reviewing the memory dump that my objects I create exist after they are cleared.</p>

<p>e.g. a simple example of what I have implemented</p>

<pre><code>private ExpandableListAdapter returnList(Context context, String[] APList) {
    if (bLogging) { //Assume true
        ArrayList&lt;String&gt; List = new ArrayList&lt;&gt;();
        foreach (AccessPoint ap: APList){
            //code initilializing and assigning param variables
            List.add(new AP(param1, param2, param3))
        }
        return (new ExpandableListAdapter(context, List));
    }
}
</code></pre>

<p><em>Please do not worry about any syntax,etc issues, this is just for understanding of my problem.</em></p>

<p>This piece of code is run by a <code>Thread</code>, sleeping every <code>500ms</code> to rescan</p>

<p>In this example, after <code>returnList()</code> has finished executing, the <code>ArrayList&lt;&gt; List</code>, <code>new AP(param...)</code> will remain as objects, taking up memory.</p>

<p>My thread loop is defined by:</p>

<pre><code>//code before

t = new Thread(new Runnable() {
        public void run() {
            handler = new Handler(context.getMainLooper());
            while (!bStopThread) {
                ThreadCounter++;

                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        if (bSafe) {
                            initWiFiArrays();  //AccessPoint Objects are created as shown in example
                            CreateSetAdapter(); //Custom ExpandableListAdapter is created, but declared and instantiated within the method
                            threadRefresh.setText("# Refreshed Times : " + String.valueOf(ThreadCounter));
                            writeResultsToFile();
                        } else
                            stopScan();
                    }
                });
                try {
                    Thread.sleep(scanInterval);
                } catch (Exception x) {
                    x.printStackTrace();
                }
            }
        }
    });
t.start();

//code after
</code></pre>

<p><strong>UPDATE:</strong></p>

<p>I resorted to clearing globally declared Lists and a scanResultCollection which contain +/- 9 items, this decreases memory taken up by 40Mb.</p>