0

In certain situations, I create an EditText, pass the value to another Fragment, and then call removeAllViews on the ViewGroup that the EditText belongs to remove EditText.

The problem is that the InputConnectionWrapper associated with the EditText is still occupying memory.

enter image description here

In the above Heap Dump, the InputConnectionWrapper is allocated over 300 and takes up considerable memory.

However, with the Heap Dump enabled, there is only one EditText in the Activity, and it is judged that the InputConnectionWrapper is not created due to the corresponding EditText.

To close the InputConnectionWrapper, I tried the following function.

    TextKeyListener.clear(editText.getText());
    editText.setHint(null);
    editText.removeTextChangedListener(this);
    editText=null;
    // The ViewGroup will then execute removeAllViews.

However, the InputConnectionWrapper seems to be allocated more over time as it is not finalized.

What is the reason InputConnectionWrapper will not be finalized?

H.Kim
  • 525
  • 4
  • 14

1 Answers1

0

I ran into the same issue found via LeakCanary giving me a chain of InputConnectionWrapper'd wrapping an EditText.

It looks like this is a bug in Android code that was fixed in Marshmallow. When I upgraded my min API version from 21 (Lollipop) to 23 (Marshmallow), the problem went away.

Jerry Sha
  • 3,931
  • 2
  • 23
  • 16