Closed moertel closed 1 year ago
Maybe assigning mIcons
to null
before assigning it to the array can solve it? - https://github.com/zixpo/candybar/blob/main/library/src/main/java/candybar/lib/adapters/IconsAdapter.java#L355
I am not sure if it will make a difference, this is the last thing I can think of
Keeping you posted: I tried a lot by now. Setting mIcons
to null, rewriting everything so it would be reusing the same ArrayList
(clearing and refilling, instead of assigning brand new lists), explicitly calling the Garbage Collector... None worked.
The interesting bit is that memory increases both when a search term is entered and when navigating back to the full list.
I'm puzzled by this. :)
It was not caused by the icons' array. It was caused by this List
of ViewHolder
.
https://github.com/zixpo/candybar/blob/55cabe98832304e677633c085b38c5b4189d951b/library/src/main/java/candybar/lib/adapters/IconsAdapter.java#L68 https://github.com/zixpo/candybar/blob/55cabe98832304e677633c085b38c5b4189d951b/library/src/main/java/candybar/lib/adapters/IconsAdapter.java#L192
Here,
https://github.com/zixpo/candybar/blob/55cabe98832304e677633c085b38c5b4189d951b/library/src/main/java/candybar/lib/adapters/IconsAdapter.java#L207-L213
I thought that removing holders on onViewRecycled
would remove all unused holders, but that was not the case. Those holders kept some reference to other bigger objects and caused memory leaks.
The new implementation doesn't hold any reference to objects that would cause memory leaks.
You're a wizard, @sarsamurmu! Thanks for tracking down and solving this issue.
When searching icons in fast succession (i.e. deleting, adding, deleting and adding characters), I can watch the memory footprint grow in AndroidStudio. If done fast enough, the device goes out of memory. If I do it more slowly, I can see the garbage collector catching up and freeing memory.
In the wild, every week or two I see a user hitting the OutOfMemoryError while searching for icons. (I have analytics implemented in my app, so I can see the actions that lead up to a crash.)
Right now I'm unsure how to solve this. Is there a way to give the garbage collector a hint that a previous search result may be completely discarded if a new search is typed in?
Stacktrace example: