• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Possible Memory Leak from using TextInputLayout

Launching my app in debug mode alongside the android studio profiler revealed something very starling.

What I've noticed is that in each activity with a TextInput layout field, the amount of allocated objects that the profiler reports is always increasing but if I to go an activity that doesn't have one, it remains constant(for the most part though).

Googling this issue revealed that the TextInputEditText widget inside the TextInputLayout is what is causing this issue(Some to do with having the recalculation and redraws each time the user types).

What are possible solutions to this issue?
 
You're worrying about a problem that doesn't exist.
To start with, Java garbage collection works by recovering memory only after the amount of used memory reaches a critical point. So when looking at profiler stats, you'll often see spikes in the memory allocation, before it's suddenly cleared by the garbage collector. That's normal.
Secondly, I'd be extremely surprised if there was a serious memory leak inside the SDK framework. If that was the case, it would have been detected and fixed long ago.
And is this causing an actual problem in your app?
What are these sources you mention that highlight a problem with this component?

Having said that, it's possible there's a problem with your code that causes objects to be permanently referenced, and therefore the memory can't be reclaimed. But without seeing your code, it's difficult to say if that's the case.
 
Here is a video showcasing what I'm talking about. You can see in the video that the number of allocated objects increases whenever I'm in a scene that has a textinputlayout widget(I've verified this because I removed all the xml code that used a textinputlayout widget and the number of allocated objects stopped increasing).

Here is a link to a stackoverflow post talking about this issue(although they talk about the edittext widget, the textinputlayout widget uses something very similar to that).

https://stackoverflow.com/questions/35780166/edittext-memory-leak

Here is another one.

https://issuetracker.google.com/issues/37085054

I'm just bringing this up because it seems very strange that the textinputlayout widget would be doing this at all but then again it might be a non issue.

If you want, I can provide you with one of my layout files so you can test it yourself.
I'm on android studio 3.0.1
 

Attachments

Last edited:
Back
Top Bottom