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:
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...
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 "";
}
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?
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.