android过多的全局引用

时间:2010-09-20 19:55:53

标签: android java-native-interface emulation

我偶尔会绊倒Android模拟器的jni全局参考限制。我试图在我的应用程序中存储大约2000个单词以及定义,并且它在两个位置中的任何一个都失败:如果我使用DOM来解析具有所有这些引用的xml文件,则当DOM将树拉入内存时它会失败。如果我使用SAX,当我到达第2000个元素时它会失败。

有没有人有关于如何禁用检查的链接(我知道它在实际的机器上不存在,我试图在内存中保留2000个小对象)?如果没有,是否有一个很好的方法来调试它?正在构建的对象是字符串:

09-20 16:24:00.278: WARN/dalvikvm(625):  1879 of Ljava/lang/String; 28B (1877 unique)

我尝试使用-nojni启动avd并使用adb设置dalvik.vm.checkjni

C:\android-sdk-windows\tools>adb shell getprop dalvik.vm.checkjni
false

虽然logcat显示“CheckJNI已关闭”,但它仍然死于globalref 2001限制。

此外,在解析部分之后,当我看到时,内存最终会返回:

09-20 16:31:23.238: DEBUG/dalvikvm(654): GC_EXPLICIT freed 1157 objects / 48208 bytes in 147ms
09-20 16:31:23.258: DEBUG/dalvikvm(654): GREF has decreased to 1799
09-20 16:31:23.278: DEBUG/dalvikvm(654): GREF has decreased to 1699
09-20 16:31:23.287: DEBUG/dalvikvm(654): GREF has decreased to 1599
09-20 16:31:23.309: DEBUG/dalvikvm(654): GREF has decreased to 1499
09-20 16:31:23.328: DEBUG/dalvikvm(654): GREF has decreased to 1399
09-20 16:31:23.338: DEBUG/dalvikvm(654): GREF has decreased to 1299
09-20 16:31:23.367: DEBUG/dalvikvm(654): GREF has decreased to 1199
09-20 16:31:23.367: DEBUG/dalvikvm(654): GREF has decreased to 1099
09-20 16:31:23.398: DEBUG/dalvikvm(654): GREF has decreased to 999
09-20 16:31:23.398: DEBUG/dalvikvm(654): GREF has decreased to 899
09-20 16:31:23.408: DEBUG/dalvikvm(654): GREF has decreased to 799
09-20 16:31:23.418: DEBUG/dalvikvm(654): GREF has decreased to 699
09-20 16:31:23.418: DEBUG/dalvikvm(654): GREF has decreased to 599
09-20 16:31:23.437: DEBUG/dalvikvm(654): GREF has decreased to 499
09-20 16:31:23.447: DEBUG/dalvikvm(654): GREF has decreased to 399
09-20 16:31:23.447: DEBUG/dalvikvm(654): GREF has decreased to 299
09-20 16:31:23.469: DEBUG/dalvikvm(654): GREF has decreased to 199

所以我不认为这是我的hashmap持有单词对象实际上是问题。我留下的唯一想法是将xml文件剪切成倍数,但这似乎是一个可能不太优雅的解决方案。

非常感谢!

2 个答案:

答案 0 :(得分:2)

这是我们基于expat的XML解析器(SAX和pull)中的一个错误:http://code.google.com/p/android/issues/detail?id=12595

答案 1 :(得分:0)

虽然比sax略慢,但使用XML Pull Parser时,过多的全局引用似乎消失了。