I in my android app I am usin开发者_开发技巧g library which wasn't designed for android - it uses a lot of memory, by creating a big amount of small local objects. Because the memory usage hits in peaks the limit of 16MB it triggers garbage collecting often. I would be fine, but running gc so often causes my refresh handler not being executed with desired delay(the method is executed less often then it should).
class RefreshHandler extends Handler {
@Override
public void handleMessage(Message msg) {
SomeActivity.this.updateView();
}
public void sleep(long delayMillis) {
this.removeMessages(0);
sendMessageDelayed(obtainMessage(0), delayMillis);
}
};
The stuff that causes garbage collecting is running in own thread. Is their any way to improve regularity of handler executing without changing library or it code?
The garbage collector in android is a stop-the-world garbage collector, so as long as the library and the Handler are in the same VM there's isn't much you can do. Maybe you can run the Handler in another app which would decouple it from the VM which the lot of GCs (and use broadcasts for the interaction with the rest)?
精彩评论