AndroidTextText memory leak

Many people notice EditText in their action, which holds a strong link to the activity even after its completion. To be clear, this EditText is inside the layout and is overpriced; there is no Listeners set. This only happens on certain devices, for example. Samsung Galaxy S4 (Android 4.2.2) and others. Many reports about this have not yet been resolved. First, here are some helpful posts. (In the end, the GC will clear this, so it's not technically a leak, but for large memory applications, it lasts a long time and will call OOM)

Samsung Android memory leak in EditText

Why EditText maintains the context of its activity in the Ice Cream sandwich

EditText causing a memory leak

Possibility of raw memory leak

These solutions do not work for all devices. It comes down to the Edittext observer. I think there may be a solution in overriding this Watcher and then a function to clear it onDestroy (). Please help here, I have been on this for several days.

Here is the MAT histogram

Memory leak

+5
android memory-leaks android-edittext
source share
2 answers

I was embarrassed about this memory leak for a very long time. But recently, I found two ways to fix this problem.

  • I found that if your TextView / EditText has the android:hint property, this cannot be. So the easiest way is to give each texture / EditText a hint property.

  • The strongest way is to flip the TextLine and find the ChangeWatcher listener, and then kill that listener.

0
source share

Try using the application context instead of the activity context in onCreateView () for this particular view (which contains any android components: textIsSelectable = "true").

 // Singleton class MyApplication extends Application { private static MyApplication mApp; @Override public void onCreate() { mApp = this; } public static MyApplication getApp() { return mApp; } } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Suggested inflater use Activity Context // So we must tu use Application Context Context context = MyApplication.getApp().getApplicationContext(); LayoutInflater myLayoutInflater = LayoutInflater.from(context); View view = myLayoutInflater.inflate(R.layout.my_view, container, false); return view; } 
-one
source share

All Articles