Issue
Steps to reproduce the problem:
The way I reproduce this problem is
- I run my android application & I enter the MainActivity
- I leave my phone idle for about ten minutes or more, having configured the device in its settings to not sleep if idle less than 30 minutes.
- While waiting, in Android Studio's "Run" tab I see messages such as this one:
Background concurrent copying GC freed 237478(18MB) AllocSpace objects, 52(1756KB) LOS objects, 69% free, 5507KB/17MB, paused 217us total 164.170ms
- After 5 to 10 messages as the one above, I see this couple of messages:
Background concurrent copying GC freed 257288(11MB) AllocSpace objects, 0(0B) LOS objects, 66% free, 6204KB/18MB, paused 86us total 165.671ms
Background young concurrent copying GC freed 217214(10MB) AllocSpace objects, 0(0B) LOS objects, 56% free, 8108KB/18MB, paused 112us total 129.379ms
- If I wait more, I keep receiving the above couple of messages and if I touch the screen nothing is interactable and the whole app seems frozen. Also, the device's "Home" & "Back" buttons don't do anything. If I minimize the app when I try to maximize it again there's a great delay and when the app finally opens, everything keeps not responding (buttons don't do anything and you can't even scroll). So, I am forced to kill the app.
Observations & Notes:
The problem described in the above steps doesn't always occur. But, when I try to reproduce it, it occurs about half of the times that the app is run.
I have run my app using the profiler while reproducing the problem and the memory consumption remains at the same level from start to finish, throughout all the above steps.
Keep in mind that I have seen and reproduced this problem in a Xiaomi Mi A2 Lite device, which has only 3GB RAM. I haven't tried to reproduce it in any other devices.
The Activity where this problem occurs contains some views with many images. When I don't populate some views from the Activity's layout with any images, then the above log messages report more free memory percentage. The problem still occurs at times but you have to leave the phone idle for much more time for the app to freeze. Also, the greater the size of the images is, the easier it is for this problem to be reproduced.
My conclusion:
I've observed that when I receive the above log messages the free memory percentage gradually decreases and the app starts freezing when it reaches values below 60%. So, I assume that the device's memory can't handle that much data and that's why the garbage collector keeps reallocating the memory for optimization purposes. Of course, the easiest solution would be to have a device with more memory or use less and smaller size images, but I'd prefer a more robust solution.
Questions:
I'd like to know if someone else has observed this same kind of behavior in their app and how they have dealt with it.
In the beginning I receive log messages that start with "Background concurrent copying GC freed" (see step 3) and after a bunch of them I receive the couple of messages (see step 4) where the first message starts with "Background concurrent copying GC freed" and the second message starts with "Background young concurrent copying GC freed". Does that "young concurrent" mean anything different or should I ignore this change?
Is there any other tool that may help me investigate this matter any further?
Solution
I solved the problem, it turns out that a colleague of mine had created a new thread that kept being alive even when idle. As a result, the message "Background young concurrent copying GC freed" appeared and the device gradually started running out of memory. So, for anyone that observes the same messages or behavior I would suggest they check analytically their app's memory consumption and especially the multi-threaded functionalities.
Answered By - Thanasis M
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.