Description
Bug description
Based on a recent issue report on inotia00's repository (which I start to reproduce 2/3 months ago):
inotia00/ReVanced_Extended#2898
YouTube start to drain battery after posting comments on any video. This lead to visible app stuttering and device overheating.
Error logs
Many GC Freed spammed in the logcat
Solution
I tried to figure out how to make a fix to prevent it, by saving some memory allocation profiles and tracking the stack calls of problematic classes. After different trying, this is what I was able to understand from this situation:
- Battery drain is caused by a memory leak in one Litho class, with many
GC Freed
spammed in the logcat. - This class manage elements like the bottom action buttons bar in fullscreen mode and other minor things.
- All Litho classes are managed by a ThreadPoolExecutor and some Thread objects created subsequently.
The fix - or the workaround, to be more clear - implementation is trivial enough:
- Set both minimum and maximum ThreadPoolExecutor threads amount to 1 and
allowCoreThreadTimeout
to true (it's set to false as default). - Set the ThreadPoolExecutor timeout to 1 and the Threads priority to 1 as well.
That's all...
I'm trying this workaround by three days, and cannot reproduce the battery drain anymore after posting comments (probably because the problematic thread is purged fast enough to prevent the memory leak).
Additional context
To find the classes: Perform a search by the string "ComponentLayoutThread"
, to find the threads classes (are two: one with obfuscated name and another named ComponentTree
), and by reference allowCoreThreadTimeout
(there is only one in the entire source code) to find the ThreadPoolExecutor.
Note: In the aformentioned class with obfuscated name, which creates the threads, there is an integer field initialized in the init
method that must be set to 1. This field is readed by another obfuscated class that create ls further Litho related threads.
Acknowledgements
- I have checked all open and closed bug reports and this is not a duplicate.
- I have chosen an appropriate title.
- All requested information has been provided properly.