Android Samsung Memory leak in EditText

2019-07-09 01:48发布

问题:

I encountered a memory leak with Samsung devices. If some activity has EditText this activity will be leaked. To show this I created a small test applications.

First Activity (called MyActivity) contains EditText and Button. By pressing a button you call finish() on first Activity and open second one.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    findViewById(R.id.goTo)).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
            Intent intent = new Intent(MyActivity.this, AnotherActivity.class);
            startActivity(intent);
        }
    });
}

When I am on second Activity I take a hprof. From Memory Analyzer I see that MyActivity is leaked because of reference from InputMethodManager

This problem occurs only in Samsung S III and Tab devices. So there is no leak in Xperia P device and others. Please help how to bypass this error.