在我的应用中经常执行android 垃圾收集,导致应用程序暂停几毫秒。这给使用该应用程序带来了难看的感觉。这是我的应用程序的输出。我不理解 为什么在收集GC的情况下,当仍有超过60%的已分配空间可供应用时 。任何人都可以帮忙解决这个问题吗?
04-30 10:37:10.024 D/dalvikvm(13590): GC_EXPLICIT freed 450K, 65% free 3918K/11072K, paused 1ms+3ms, total 22ms
04-30 10:37:10.076 D/Mono (13590): GC_OLD_BRIDGE num-objects 6431 num_hash_entries 6552 sccs size 6552 init 0.00ms df1 11.73ms sort 2.44ms dfs2 2.69ms setup-cb 3.31ms free-data 2.83ms links 123/123/134/2 dfs passes 13106/6675
04-30 10:37:10.076 D/Mono (13590): GC_MINOR: (Nursery full) pause 67.65ms, total 67.77ms, bridge 149.55ms promoted 1344K major 1584K los 460K
04-30 10:37:28.900 D/dalvikvm(13590): GC_EXPLICIT freed 414K, 65% free 3880K/11072K, paused 1ms+3ms, total 20ms
04-30 10:37:28.962 D/Mono (13590): GC_OLD_BRIDGE num-objects 8293 num_hash_entries 8437 sccs size 8437 init 0.00ms df1 14.18ms sort 3.85ms dfs2 3.74ms setup-cb 4.57ms free-data 3.90ms links 144/144/144/1 dfs passes 16874/8581
04-30 10:37:28.962 D/Mono (13590): GC_MINOR: (Nursery full) pause 75.21ms, total 75.35ms, bridge 179.08ms promoted 928K major 2512K los 1078K
04-30 10:37:40.035 D/dalvikvm(13590): GC_EXPLICIT freed 415K, 65% free 3880K/11072K, paused 2ms+2ms, total 21ms
04-30 10:37:40.109 D/Mono (13590): GC_OLD_BRIDGE num-objects 8321 num_hash_entries 8495 sccs size 8495 init 0.00ms df1 20.13ms sort 3.42ms dfs2 3.73ms setup-cb 4.82ms free-data 3.88ms links 174/174/174/1 dfs passes 16990/8669
04-30 10:37:40.109 D/Mono (13590): GC_MINOR: (Nursery full) pause 78.00ms, total 78.13ms, bridge 195.10ms promoted 848K major 3360K los 1078K
04-30 10:37:46.275 D/dalvikvm(13590): GC_EXPLICIT freed 469K, 65% free 3880K/11072K, paused 2ms+2ms, total 20ms
04-30 10:37:46.339 D/Mono (13590): GC_OLD_BRIDGE num-objects 8366 num_hash_entries 8545 sccs size 8545 init 0.00ms df1 16.65ms sort 3.41ms dfs2 3.75ms setup-cb 4.60ms free-data 3.73ms links 179/179/179/1 dfs passes 17090/8724
04-30 10:37:46.339 D/Mono (13590): GC_MINOR: (Nursery full) pause 99.26ms, total 99.46ms, bridge 180.23ms promoted 736K major 4096K los 1078K
04-30 10:37:52.764 D/dalvikvm(13590): GC_EXPLICIT freed 413K, 65% free 3880K/11072K, paused 2ms+3ms, total 24ms
04-30 10:37:52.828 D/Mono (13590): GC_OLD_BRIDGE num-objects 8420 num_hash_entries 10901 sccs size 9914 init 0.00ms df1 23.45ms sort 4.95ms dfs2 33.94ms setup-cb 4.97ms free-data 9.42ms links 5543/5543/201386/155 dfs passes 24864/15457
04-30 10:37:52.828 D/Mono (13590): GC_MINOR: (Nursery full) pause 77.37ms, total 77.50ms, bridge 222.91ms promoted 720K major 4816K los 1078K
04-30 10:37:59.867 D/dalvikvm(13590): GC_EXPLICIT freed 429K, 65% free 3880K/11072K, paused 2ms+3ms, total 22ms
04-30 10:37:59.932 D/Mono (13590): GC_OLD_BRIDGE num-objects 8468 num_hash_entries 10955 sccs size 9968 init 0.00ms df1 23.14ms sort 8.74ms dfs2 37.68ms setup-cb 5.77ms free-data 10.75ms links 5552/5552/206268/159 dfs passes 24975/15520
04-30 10:37:59.932 D/Mono (13590): GC_MINOR: (Nursery full) pause 79.11ms, total 79.28ms, bridge 237.01ms promoted 688K major 5504K los 2468K
04-30 10:38:06.707 D/dalvikvm(13590): GC_EXPLICIT freed 441K, 65% free 3880K/11072K, paused 2ms+3ms, total 23ms
04-30 10:38:06.773 D/Mono (13590): GC_OLD_BRIDGE num-objects 8471 num_hash_entries 10933 sccs size 9946 init 0.00ms df1 24.23ms sort 7.11ms dfs2 36.40ms setup-cb 5.83ms free-data 10.35ms links 5509/5509/188815/146 dfs passes 24913/15455
04-30 10:38:06.773 D/Mono (13590): GC_MINOR: (Nursery full) pause 83.46ms, total 83.57ms, bridge 233.86ms promoted 640K major 6144K los 2468K
04-30 10:38:12.649 D/dalvikvm(13590): GC_EXPLICIT freed 436K, 65% free 3879K/11072K, paused 1ms+2ms, total 20ms
04-30 10:38:12.717 D/Mono (13590): GC_OLD_BRIDGE num-objects 8532 num_hash_entries 10998 sccs size 10011 init 0.00ms df1 25.97ms sort 8.41ms dfs2 38.58ms setup-cb 6.02ms free-data 10.75ms links 5518/5518/187236/144 dfs passes 25048/15529
04-30 10:38:12.717 D/Mono (13590): GC_MINOR: (Nursery full) pause 98.05ms, total 98.50ms, bridge 234.75ms promoted 656K major 6800K los 2468K
04-30 10:38:20.459 D/dalvikvm(13590): GC_EXPLICIT freed 465K, 65% free 3880K/11072K, paused 3ms+3ms, total 24ms
04-30 10:38:20.553 D/Mono (13590): GC_OLD_BRIDGE num-objects 8513 num_hash_entries 10980 sccs size 9993 init 0.00ms df1 26.31ms sort 6.49ms dfs2 36.70ms setup-cb 9.15ms free-data 14.76ms links 5519/5519/187237/144 dfs passes 25012/15512
04-30 10:38:20.553 D/Mono (13590): GC_MINOR: (Nursery full) pause 170.23ms, total 170.36ms, bridge 287.15ms promoted 592K major 7392K los 2468K
04-30 10:38:20.613 I/Choreographer(13590): Skipped 35 frames! The application may be doing too much work on its main thread.
04-30 10:38:28.985 D/dalvikvm(13590): GC_EXPLICIT freed 422K, 65% free 3880K/11072K, paused 2ms+2ms, total 22ms
04-30 10:38:29.057 D/Mono (13590): GC_OLD_BRIDGE num-objects 8658 num_hash_entries 11130 sccs size 10143 init 0.00ms df1 24.92ms sort 6.66ms dfs2 38.72ms setup-cb 5.76ms free-data 10.70ms links 5531/5531/202881/157 dfs passes 25319/15674
04-30 10:38:29.057 D/Mono (13590): GC_MINOR: (Nursery full) pause 86.76ms, total 86.90ms, bridge 246.82ms promoted 592K major 7984K los 2468K
04-30 10:38:37.678 D/dalvikvm(13590): GC_EXPLICIT freed 464K, 65% free 3880K/11072K, paused 2ms+2ms, total 21ms
04-30 10:38:37.745 D/Mono (13590): GC_OLD_BRIDGE num-objects 8717 num_hash_entries 11155 sccs size 10168 init 0.00ms df1 25.41ms sort 6.09ms dfs2 36.01ms setup-cb 5.71ms free-data 11.76ms links 5483/5483/178115/137 dfs passes 25355/15651
04-30 10:38:37.745 D/Mono (13590): GC_MINOR: (Nursery full) pause 83.86ms, total 84.08ms, bridge 236.66ms promoted 544K major 8528K los 2468K
04-30 10:38:45.967 D/dalvikvm(13590): GC_EXPLICIT freed 421K, 65% free 3880K/11072K, paused 2ms+3ms, total 21ms
04-30 10:38:46.037 D/Mono (13590): GC_OLD_BRIDGE num-objects 8744 num_hash_entries 11199 sccs size 10212 init 0.00ms df1 26.69ms sort 6.04ms dfs2 34.30ms setup-cb 5.41ms free-data 10.19ms links 5514/5514/195019/150 dfs passes 25457/15726
04-30 10:38:46.037 D/Mono (13590): GC_MINOR: (Nursery full) pause 82.99ms, total 83.20ms, bridge 242.09ms promoted 608K major 9136K los 2468K
答案 0 :(得分:0)
您发布的日志显示您在主线程上做了太多工作,这导致应用程序挂起而不是GC消息或偶尔运行垃圾收集器。
确保你没有创建短生活自定义线程来做像ui或任何其他工作。使用Async Taks来执行您的工作。
其次不要在UI线程上做很多事情,这会导致应用程序挂起几秒钟。
Third Dont Call System.gc();表示要运行的垃圾收集器。
不幸的是,你无法使用你自己的代码来停止垃圾收集器,就像在系统架构中那样。
GC_FOR_MALLOC表示已触发GC,因为堆上没有足够的内存来执行分配。在创建新对象时可能会触发。
进一步请阅读这些参考消息所说的内容,以便更好地了解每条消息所描述的内容。
GC_EXPLICIT表示已明确要求收集垃圾收集器,而不是由堆中的高水位标记触发。发生在整个地方,但很可能是在一个线程被杀死或者绑定器通信被取消时。
还有其他几个:
GC_CONCURRENT当堆已达到要收集的特定数量的对象时触发。
GC_EXTERNAL_ALLOC表示虚拟机正在尝试减少可收集对象使用的内存量,以便为更多不可收集的内容腾出空间。
在Android的更高版本中,第一个事件发生了名称更改。它现在称为“GC_FOR_ALLOC”。还有一个新的事件,虽然在现代手机中非常罕见:GC_BEFORE_OOM意味着系统内存运行非常低,并且执行了最终的GC,以避免调用低内存杀手。
答案 1 :(得分:0)
Set this property on your ListView and it will solve this issue with the GC running constantly while scrolling:
CachingStrategy="RecycleElement"