Memory leak during orientation change with inner class
<p>I encounter a memory leak problem on the orientation change of my Activity. With the android tools and the Memory Analysis Perspective (<a href="http://ttlnews.blogspot.com/2010/01/attacking-memory-problems-on-android.html" rel="nofollow">http://ttlnews.blogspot.com/2010/01/attacking-memory-problems-on-android.html</a>) I finally found the following problem:</p>

<p>During orientation change I save the data I need into an Inner class as you can see in the folowing code:</p>

<pre><code>public class TestOrientation extends Activity {

    private ActivityData mData;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mylayout);
        ...
        mData = (ActivityData) getLastNonConfigurationInstance();
        ...
    }

    @Override
    public Object onRetainNonConfigurationInstance() {
        return new ActivityData(dataToSave1, dataToSave2);
    }

    private class ActivityData {

        public int mDataToSave1;
        public String mDataToSave2;

        public ActivityData(int dataToSave1, String dataToSave2) {
            mDataToSave1 = dataToSave1;
            mDataToSave2 = dataToSave2;
        }
    }
}
</code></pre>

<p>In the memory Memory Analysis Perspective I can see that the attribute mData keeps a reference to the activity Context so it's never deallocated. After a few orientation change I have a recursive reference:</p>

<p><img src="http://i.stack.imgur.com/DjQ1l.png" alt="sreenshot of MAP"></p>

<p>To solve it I've declared the ActivityData in a separate file, but if somebody can explain me why I encounter this problem I would be great!</p>
