This happened when I was working on the abnormal memory usage tracking feature in Android SDK for Finotes. For all those who are new to Finotes, Finotes is an SDK for Android and iOS capable of detecting memory-related issues, crashes and API errors and more, with less than 5 minutes of integration to any mobile and wearable app.
We have a test application with a single activity containing two Text Views, three Buttons and one EditText that we used to test our Android SDK during development.
Optimizing memory and SDK size is an activity I do religiously for every release. For version 1.0 delta added to the apk by Finotes was around 400 KB. Well, that was acceptable when I compared the metric with some of our competitors. But I wanted to push Finotes to its limits, so during the development of version 2.0 myself and my co-founder Robin sat for a week in a stretch, optimized classes and removed lots of unwanted code (no, we didn’t remove any feature 😊) and brought down the delta to 68 KB.
Wow!.. That’s only a fraction of the original size. Well, we did it.
Then we moved on to optimizing the memory usage of Finotes SDK and on course of doing the same, we found something really interesting.
Android Studio profiler showed the memory allocations kept on increasing even after SDK initialization. 3,800 objects got allocated within 12.396 seconds adding 307 object allocations every second.
Finotes is designed in such a way that it remains silent until an issue is detected, but still memory allocations kept on increasing. So I started digging. As the test application is a fairly straight forward app, I naturally thought the zombie allocations were from Finotes SDK.
IT WAS NOT.
I removed all elements from my test app. Then I ran the profiler again. There were no zombie allocations. All good.
Then I started adding each of the elements back and when ‘EditText’ was back and in focus within my activity, zombie allocations were back. I found the culprit. 🤦♂️
Bottom line. When EditText gets inflated in an Activity, it starts zombie memory allocations, which pile up.
We originally noticed this issue in Android 6, and it is still an issue in Android 9.
Surprisingly there is no solution to this issue. This leak in EditText is something we have to live with. Yes, it’s irritating for a developer 😊.