我正在将 phonegap 用于一个项目,并且有一次我需要获取用户的整个地址簿。它在 iOS 上运行良好,但在 android 上,有时需要 2 秒,有时长达 20 秒。
GC_CONCURRENT
当需要这么多时间时,我会收到很多GC_FOR_ALLOC
LogCat 消息。
05-07 18:01:40.869: D/dalvikvm(17847): GC_CONCURRENT freed 379K, 16% free 9756K/11527K, paused 24ms+23ms, total 97ms
05-07 18:01:42.650: D/dalvikvm(17847): GC_CONCURRENT freed 288K, 15% free 9865K/11527K, paused 30ms+21ms, total 98ms
05-07 18:01:44.132: D/dalvikvm(17847): GC_CONCURRENT freed 292K, 14% free 9972K/11527K, paused 26ms+22ms, total 114ms
05-07 18:01:46.064: D/dalvikvm(17847): GC_CONCURRENT freed 276K, 13% free 10121K/11591K, paused 24ms+14ms, total 116ms
05-07 18:01:47.425: D/dalvikvm(17847): GC_CONCURRENT freed 246K, 13% free 10273K/11719K, paused 13ms+12ms, total 65ms
05-07 18:01:49.197: D/dalvikvm(17847): GC_CONCURRENT freed 335K, 13% free 10368K/11911K, paused 14ms+16ms, total 72ms
05-07 18:01:50.638: D/dalvikvm(17847): GC_FOR_ALLOC freed 83K, 14% free 10405K/11975K, paused 32ms, total 32ms
05-07 18:01:51.329: D/dalvikvm(17847): GC_FOR_ALLOC freed 68K, 14% free 10438K/12103K, paused 37ms, total 37ms
05-07 18:01:51.329: I/dalvikvm-heap(17847): Grow heap (frag case) to 11.436MB for 130826-byte allocation
05-07 18:01:51.379: D/dalvikvm(17847): GC_FOR_ALLOC freed 0K, 14% free 10566K/12231K, paused 49ms, total 49ms
05-07 18:01:52.480: D/dalvikvm(17847): GC_FOR_ALLOC freed 105K, 15% free 10487K/12231K, paused 34ms, total 34ms
05-07 18:01:52.490: I/dalvikvm-heap(17847): Grow heap (frag case) to 11.545MB for 196234-byte allocation
05-07 18:01:52.520: D/dalvikvm(17847): GC_FOR_ALLOC freed 127K, 16% free 10551K/12423K, paused 36ms, total 36ms
05-07 18:01:55.303: D/dalvikvm(17847): GC_FOR_ALLOC freed 233K, 15% free 10658K/12423K, paused 33ms, total 33ms
05-07 18:01:55.363: D/dalvikvm(17847): GC_FOR_ALLOC freed 1039K, 21% free 9837K/12423K, paused 36ms, total 36ms
我查了一下,发现它与内存释放有关。不幸的是,这不取决于我的代码。生成所有这些消息的代码是cordova 框架的一部分。
现在有什么办法可以加快联系人的获取速度,或者避免那些“内存泄漏”吗?
cordova 项目是开源的,所以这里是他们的 github 的链接:
https://github.com/apache/cordova-android/tree/master/framework/src/org/apache/cordova
虽然这对我来说太重了。我在 Java 方面不够好,不知道我可以做些什么来避免这些内存问题。
也许我对此无能为力。
还是非常感谢 !