I've jumped to Android project, which allocated a lot of Bitmaps . I've met there this code:
System.gc();
try {
b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
} catch (OutOfMemoryError e) {
System.gc();
try {
Thread.sleep(100);
} catch (InterruptedException e1) {
log.error("Failed to sleep.");
}
try {
b = Bitmap.createBitmap(w, h, Bitmap.Config.RGB_565);
} catch (OutOfMemoryError e1) {
log.error("Error", e1);
}
}
and I've started to wonder if it have any sense to sleep Thread for a while after System.gc() was called? I've made some research about System.gc() on my own and I found few info about how it works:
Patrick Dubroy said that garbage collecting on Android >= Honeycomb it takes about 5ms (it is optimized and concurrent).
Moreover in few places I found info, that calling System.gc() is just a suggestion to run garbage collector. Above code is part of project which is enhanced for last 2 years and I suppose that this Thread.sleep is some workaround for problems which occurs on this time.
Any ideas?