Fixed issue 309

- do not use bitmap.recycle() instead let the gc do it's job. OsmAnd
has more threads so we can get time to time into conflict with already
recycled bitmap
This commit is contained in:
Pavol Zibrita 2011-01-26 03:01:43 +01:00
parent e7d9a65c86
commit 05fb318048
4 changed files with 5 additions and 45 deletions

View file

@ -713,13 +713,7 @@ public class ResourceManager {
public synchronized void updateMapSource(boolean useVectorMap, ITileSource source){
log.info("Clear cache with new source " + cacheOfImages.size()); //$NON-NLS-1$
ArrayList<String> list = new ArrayList<String>(cacheOfImages.keySet());
for (int i = 0; i < list.size(); i ++) {
Bitmap bmp = cacheOfImages.remove(list.get(i));
if(bmp != null){
bmp.recycle();
}
}
cacheOfImages.clear();
renderer.clearCache();
if(source == null || source.getBitDensity() == 0){
maxImgCacheSize = 32;
@ -735,10 +729,7 @@ public class ResourceManager {
ArrayList<String> list = new ArrayList<String>(cacheOfImages.keySet());
// remove first images (as we think they are older)
for (int i = 0; i < list.size() /2; i ++) {
Bitmap bmp = cacheOfImages.remove(list.get(i));
if(bmp != null){
bmp.recycle();
}
cacheOfImages.remove(list.get(i));
}
}

View file

@ -355,12 +355,8 @@ public class MapRenderRepositories {
boolean stepByStep = OsmandSettings.isUsingStepByStepRendering(prefs);
// 1. generate image step by step
if (stepByStep) {
Bitmap oldBmp = this.bmp;
this.bmp = bmp;
this.bmpLocation = tileRect;
if (oldBmp != null) {
oldBmp.recycle();
}
}
renderer.generateNewBitmap(currentRenderingContext, cObjects, bmp,
@ -374,12 +370,8 @@ public class MapRenderRepositories {
// 2. replace whole image
if (!stepByStep) {
Bitmap oldBmp = this.bmp;
this.bmp = bmp;
this.bmpLocation = tileRect;
if (oldBmp != null) {
oldBmp.recycle();
}
}
if(OsmandSettings.isDebugRendering(context)){
final String msg = "Search done in "+ searchTime+" ms\nRendering done in "+ renderingTime+ " ms"; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
@ -422,7 +414,6 @@ public class MapRenderRepositories {
cObjects = new ArrayList<BinaryMapDataObject>();
cObjectsBox = new RectF();
if(bmp != null){
bmp.recycle();
bmp = null;
}
requestedBox = bmpLocation = null;

View file

@ -5,7 +5,6 @@ import gnu.trove.map.hash.TFloatObjectHashMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
@ -642,13 +641,7 @@ public class OsmandRenderer {
public void clearCachedResources(){
Collection<Bitmap> values = new ArrayList<Bitmap>(cachedIcons.values());
cachedIcons.clear();
for(Bitmap b : values){
if(b != null){
b.recycle();
}
}
shaders.clear();
}

View file

@ -6,7 +6,6 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
@ -152,10 +151,7 @@ public class YandexTrafficLayer implements OsmandMapLayer {
}
}
for(String s : unusedTiles){
Bitmap bmp = tiles.remove(s);
if(bmp != null){
bmp.recycle();
}
tiles.remove(s);
}
for (int i = tMinX; i <= tMaxX; i++) {
for (int j = tMinY; j <= tMaxY; j++) {
@ -173,12 +169,7 @@ public class YandexTrafficLayer implements OsmandMapLayer {
} catch (IOException e) {
log.error("IOException", e); //$NON-NLS-1$
} catch (OutOfMemoryError e) {
for(String s : new ArrayList<String>(tiles.keySet())){
Bitmap bmp = tiles.remove(s);
if(bmp != null){
bmp.recycle();
}
}
tiles.clear();
System.gc();
if(callInd == 0){
updateCachedImages(tMinX, tMaxX, tMinY, tMaxY, tZoom, 1);
@ -272,13 +263,7 @@ public class YandexTrafficLayer implements OsmandMapLayer {
}
private void clearCache() {
ArrayList<String> l = new ArrayList<String>(tiles.keySet());
for(String k : l){
Bitmap b = tiles.remove(k);
if(b != null){
b.recycle();
}
}
tiles.clear();
}