Suspending all threads took: ms warning using Threads - Android

后端 未结 1 1158
离开以前
离开以前 2021-02-16 00:00

I have 2 Threads that make some network computation. When I run my app and after starting my second Thread I get a:

Suspending all thread

相关标签:
1条回答
  • 2021-02-16 00:24

    The first line is basically saying that the garbage collector (GC) decided it needed to suspend all threads to do some of its work (such as relocating variables) and that took some time. Normally there's a number there.

    The second line is the result of the collection. It freed a fair amount of memory, and you now have 1/3 of your heap free. It required your app to be paused for 2ms, and in total spent 127 ms collecting garbage.

    GC in and of itself isn't bad. But if you're doing it all the time, either you're doing something with lots of memory required or you're doing something inefficiently. Heavy string parsing, especially for something like JSoup, can cause lots of small objects (mainly strings) to be made that really required cleanup quickly on a small memory device like a phone, so it isn't surprising to see here.

    Basically, this is only a problem if you're getting performance hiccups from GC or if you're going OOM at some point. If neither of those are happening, I wouldn't worry about this yet.

    0 讨论(0)
提交回复
热议问题