Xamarin Android GC卡住了

时间:2017-05-18 12:12:37

标签: xamarin garbage-collection xamarin.android

我的应用程序在重复用户操作后挂起。 一开始我看到GC输出:

05-18 14:48:05.599 I/art     ( 2985): Explicit concurrent mark sweep GC freed 25278(1141KB) AllocSpace objects, 0(0B) LOS objects, 21% free, 14MB/18MB, paused 610us total 23.887ms
05-18 14:48:05.606 D/Mono    ( 2985): GC_TAR_BRIDGE bridges 3478 objects 3478 opaque 0 colors 3478 colors-bridged 3478 colors-visible 3478 xref 0 cache-hit 0 cache-semihit 0 cache-miss 0 setup 0.29ms tarjan 0.46ms scc-setup 0.29ms gather-xref 0.04ms xref-setup 0.02ms cleanup 0.19ms
05-18 14:48:05.606 D/Mono    ( 2985): GC_BRIDGE: Complete, was running for 36.70ms
05-18 14:48:05.606 D/Mono    ( 2985): GC_MINOR: (Nursery full) time 10.47ms, stw 11.24ms promoted 534K major size: 7568K in use: 6770K los size: 4252K in use: 3668K
05-18 14:48:10.670 I/art     ( 2985): Explicit concurrent mark sweep GC freed 25789(1168KB) AllocSpace objects, 0(0B) LOS objects, 20% free, 15MB/19MB, paused 645us total 25.123ms
05-18 14:48:10.677 D/Mono    ( 2985): GC_TAR_BRIDGE bridges 3335 objects 3335 opaque 0 colors 3335 colors-bridged 3335 colors-visible 3335 xref 0 cache-hit 0 cache-semihit 0 cache-miss 0 setup 0.09ms tarjan 0.43ms scc-setup 0.31ms gather-xref 0.04ms xref-setup 0.02ms cleanup 0.16ms
05-18 14:48:10.677 D/Mono    ( 2985): GC_BRIDGE: Complete, was running for 37.47ms
05-18 14:48:10.677 D/Mono    ( 2985): GC_MINOR: (Nursery full) time 9.10ms, stw 9.85ms promoted 519K major size: 8112K in use: 7290K los size: 4252K in use: 3668K
05-18 14:48:14.784 I/art     ( 2985): Explicit concurrent mark sweep GC freed 25119(1142KB) AllocSpace objects, 0(0B) LOS objects, 19% free, 16MB/20MB, paused 673us total 26.589ms
05-18 14:48:14.791 D/Mono    ( 2985): GC_TAR_BRIDGE bridges 3367 objects 3367 opaque 0 colors 3367 colors-bridged 3367 colors-visible 3367 xref 0 cache-hit 0 cache-semihit 0 cache-miss 0 setup 0.09ms tarjan 0.45ms scc-setup 0.28ms gather-xref 0.04ms xref-setup 0.02ms cleanup 0.16ms
05-18 14:48:14.791 D/Mono    ( 2985): GC_BRIDGE: Complete, was running for 38.79ms
05-18 14:48:14.791 D/Mono    ( 2985): GC_MINOR: (Nursery full) time 9.61ms, stw 10.30ms promoted 523K major size: 8624K in use: 7814K los size: 4252K in use: 3668K

一段时间后,应用程序挂起,我在日志中看到很多这样的行:

05-18 14:48:15.589 I/monodroid-gc( 2985): 46080 outstanding GREFs. Performing a full GC!
05-18 14:48:15.685 I/art     ( 2985): Explicit concurrent mark sweep GC freed 10815(715KB) AllocSpace objects, 0(0B) LOS objects, 19% free, 16MB/20MB, paused 389us total 23.169ms
05-18 14:48:16.107 D/Mono    ( 2985): GC_TAR_BRIDGE bridges 45917 objects 46071 opaque 842 colors 45915 colors-bridged 45915 colors-visible 45915 xref 369 cache-hit 0 cache-semihit 0 cache-miss 0 setup 0.86ms tarjan 6.34ms scc-setup 3.96ms gather-xref 0.40ms xref-setup 0.09ms cleanup 1.96ms
05-18 14:48:16.108 D/Mono    ( 2985): GC_BRIDGE: Complete, was running for 487.45ms
05-18 14:48:16.108 D/Mono    ( 2985): GC_MAJOR: (user request) time 25.62ms, stw 28.16ms los size: 4252K in use: 1631K
05-18 14:48:16.108 D/Mono    ( 2985): GC_MAJOR_SWEEP: major size: 6128K in use: 4929K
05-18 14:48:16.990 I/monodroid-gc( 2985): 46080 outstanding GREFs. Performing a full GC!
05-18 14:48:17.085 I/art     ( 2985): Explicit concurrent mark sweep GC freed 4804(222KB) AllocSpace objects, 0(0B) LOS objects, 19% free, 16MB/20MB, paused 513us total 24.407ms
05-18 14:48:17.140 D/Mono    ( 2985): GC_TAR_BRIDGE bridges 45919 objects 45983 opaque 291 colors 45917 colors-bridged 45917 colors-visible 45917 xref 175 cache-hit 0 cache-semihit 0 cache-miss 0 setup 0.86ms tarjan 6.48ms scc-setup 3.75ms gather-xref 0.41ms xref-setup 0.09ms cleanup 1.97ms
05-18 14:48:17.140 D/Mono    ( 2985): GC_BRIDGE: Complete, was running for 121.70ms
05-18 14:48:17.140 D/Mono    ( 2985): GC_MAJOR: (user request) time 26.42ms, stw 28.16ms los size: 4252K in use: 1631K
05-18 14:48:17.140 D/Mono    ( 2985): GC_MAJOR_SWEEP: major size: 6128K in use: 4931K
05-18 14:48:17.147 I/monodroid-gc( 2985): 46080 outstanding GREFs. Performing a full GC!
05-18 14:48:17.257 I/art     ( 2985): Explicit concurrent mark sweep GC freed 125(5KB) AllocSpace objects, 0(0B) LOS objects, 19% free, 16MB/20MB, paused 852us total 34.530ms
05-18 14:48:17.713 D/Mono    ( 2985): GC_TAR_BRIDGE bridges 45935 objects 45999 opaque 291 colors 45933 colors-bridged 45933 colors-visible 45933 xref 175 cache-hit 0 cache-semihit 0 cache-miss 0 setup 0.86ms tarjan 6.64ms scc-setup 3.62ms gather-xref 0.40ms xref-setup 0.09ms cleanup 2.13ms
05-18 14:48:17.713 D/Mono    ( 2985): GC_BRIDGE: Complete, was running for 539.05ms
05-18 14:48:17.713 D/Mono    ( 2985): GC_MAJOR_SWEEP: major size: 6128K in use: 4835K
05-18 14:48:17.713 D/Mono    ( 2985): GC_MAJOR: (user request) time 24.92ms, stw 26.12ms los size: 4252K in use: 1579K

似乎GC尝试释放资源但不能。什么对象试图破坏? 有人可以向我解释发生了什么事吗?

1 个答案:

答案 0 :(得分:0)

您发布的日志中的条目用于GC(垃圾收集),即从堆上不再使用的对象中回收内存。

有两种类型的GC在那里发生:

1)android运行时GC(用“I / art”表示)

2)MONO / .NET运行时GC(用“D / Mono”表示)

每个运行时(Android vs. .NET / Mono)都有自己的托管内存堆,它负责清理以确保没有内存“泄漏”。

看起来GC确实频繁发生,因此应用程序可能正在等待GC,这一直在不断发生。