问题描述
我有一个使用以XML序列化的Android应用程序。该应用程序运行在我还没有滞后测试它在所有真正的设备很好,但是当在模拟器上运行,在每个启动应用程序的约3分钟运行垃圾收集踢。
I have an Android app that uses the SimpleFramework for XML serialization. The app runs fine on all real devices I have tested it on with no lags, but when run on the emulator, the garbage collector kicks in a runs for about about 3 minutes on each launch of the app.
下面是我迄今观察到的:
Here is what I have observed so far:
- 垃圾收集踢在短短的序列化对象到XML之前
- 它只是之前的第一个对象是序列化并通过网络发送,并且不会发生的连续通话情况。
- 连载code是在被打包并添加作为项目的.jar文件中一个单独的库。
下面是LogCat中的输出:
Here is the output from LogCat:
07-27 08:17:10.275: D/dalvikvm(682): GC_FOR_MALLOC freed 10179 objects / 482344 bytes in 32ms
07-27 08:17:10.435: D/dalvikvm(682): GC_FOR_MALLOC freed 13927 objects / 535968 bytes in 33ms
....... About 300 more similar entries...
下面是code我presently使用序列化:
Here is the code I'm presently using for serialization:
public String fromElement(Object request) {
Writer writer = new StringWriter();
try {
serializer.write(request, writer);
String res = writer.toString();
Log.d(LOG_TAG, res);
return writer.toString();
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
显然,这占用了大量的时间,每次我做我的code的改变并重新部署应用程序。有没有其他人使用时libaray遇到过,如果是这样,有一些方法可以让我prevent每一次蹬GC我启动的应用程序(从日食)?将增加堆(目前为 vm.heapSize = 24
)帮助?还是有不同的解决方案?
Obviously, this is taking up a lot of time, each time I make a change in my code and redeploy the app. Has anyone else experienced this when using the libaray, and if so, is there some way I can prevent the GC from kicking in each time I launch the app (from eclipse)? Would increasing the heap (currently set at vm.heapSize=24
) help? Or is there a different solution?
推荐答案
您需要升级到2.6.7,还有现在的注释处理完成pretty重大变化。事实证明,Android有一个带注释的相当好知道的问题,关于奇怪的是一个坏java.lang.reflect.Method.equals(对象)的实现。简单2.6.7缓存得多注释处理,应该会好很多。
You need to upgrade to 2.6.7, there are pretty major changes to now annotation processing is done. It turns out Android has a fairly well know problem with annotations, relating strangely enough to a bad java.lang.reflect.Method.equals(Object) implementation. Simple 2.6.7 caches much more of the annotation processing and should be much better.
这篇关于过度的垃圾收集(GC_FOR_MALLOC)在Android模拟器使用simpleframework时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!