fix leak of prefetched parent tiles
This commit is contained in:
parent
d80534a20f
commit
53e6b6537f
@ -67,18 +67,18 @@ public class TileManager {
|
|||||||
private volatile int mTilesForUpload;
|
private volatile int mTilesForUpload;
|
||||||
|
|
||||||
// new tile jobs for MapWorkers
|
// new tile jobs for MapWorkers
|
||||||
private ArrayList<JobTile> mJobs;
|
private final ArrayList<JobTile> mJobs;
|
||||||
|
|
||||||
// counter to check whether current TileSet has changed
|
// counter to check whether current TileSet has changed
|
||||||
private static int mUpdateSerial;
|
private static int mUpdateSerial;
|
||||||
|
|
||||||
// lock for TileSets while updating MapTile locks
|
// lock for TileSets while updating MapTile locks
|
||||||
private Object mTilelock = new Object();
|
private final Object mTilelock = new Object();
|
||||||
|
|
||||||
private TileSet mCurrentTiles;
|
private TileSet mCurrentTiles;
|
||||||
/* package */TileSet mNewTiles;
|
/* package */TileSet mNewTiles;
|
||||||
|
|
||||||
private float[] mTileCoords = new float[8];
|
private final float[] mTileCoords = new float[8];
|
||||||
|
|
||||||
public TileManager(MapView mapView) {
|
public TileManager(MapView mapView) {
|
||||||
mMapView = mapView;
|
mMapView = mapView;
|
||||||
@ -187,8 +187,10 @@ public class TileManager {
|
|||||||
mMapView.render();
|
mMapView.render();
|
||||||
|
|
||||||
int remove = mTilesCount - GLRenderer.CACHE_TILES;
|
int remove = mTilesCount - GLRenderer.CACHE_TILES;
|
||||||
|
|
||||||
if (remove > CACHE_THRESHOLD ||
|
if (remove > CACHE_THRESHOLD ||
|
||||||
mTilesForUpload > MAX_TILES_IN_QUEUE)
|
mTilesForUpload > MAX_TILES_IN_QUEUE)
|
||||||
|
|
||||||
limitCache(mapPosition, remove);
|
limitCache(mapPosition, remove);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -330,25 +332,8 @@ public class TileManager {
|
|||||||
if (tile == null) {
|
if (tile == null) {
|
||||||
tile = new MapTile(x, y, zoomLevel);
|
tile = new MapTile(x, y, zoomLevel);
|
||||||
QuadTree.add(tile);
|
QuadTree.add(tile);
|
||||||
|
|
||||||
if (mTilesSize == mTiles.length) {
|
|
||||||
if (mTilesSize > mTilesCount) {
|
|
||||||
//Log.d(TAG, "repack: " + mTiles.length + " / " + mTilesCount);
|
|
||||||
TileDistanceSort.sort(mTiles, 0, mTilesSize);
|
|
||||||
mTilesSize = mTilesCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mTilesSize > mTiles.length - 10) {
|
|
||||||
//Log.d(TAG, "realloc tiles");
|
|
||||||
MapTile[] tmp = new MapTile[mTiles.length + 10];
|
|
||||||
System.arraycopy(mTiles, 0, tmp, 0, mTilesCount);
|
|
||||||
mTiles = tmp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mTiles[mTilesSize++] = tile;
|
|
||||||
mJobs.add(tile);
|
mJobs.add(tile);
|
||||||
mTilesCount++;
|
addToCache(tile);
|
||||||
|
|
||||||
} else if (!tile.isActive()) {
|
} else if (!tile.isActive()) {
|
||||||
mJobs.add(tile);
|
mJobs.add(tile);
|
||||||
@ -363,7 +348,7 @@ public class TileManager {
|
|||||||
QuadTree.add(p);
|
QuadTree.add(p);
|
||||||
p.state = STATE_LOADING;
|
p.state = STATE_LOADING;
|
||||||
mJobs.add(p);
|
mJobs.add(p);
|
||||||
|
addToCache(p);
|
||||||
} else if (!p.isActive()) {
|
} else if (!p.isActive()) {
|
||||||
p.state = STATE_LOADING;
|
p.state = STATE_LOADING;
|
||||||
mJobs.add(p);
|
mJobs.add(p);
|
||||||
@ -373,6 +358,27 @@ public class TileManager {
|
|||||||
return tile;
|
return tile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addToCache(MapTile tile) {
|
||||||
|
|
||||||
|
if (mTilesSize == mTiles.length) {
|
||||||
|
if (mTilesSize > mTilesCount) {
|
||||||
|
Log.d(TAG, "repack: " + mTiles.length + " / " + mTilesCount);
|
||||||
|
TileDistanceSort.sort(mTiles, 0, mTilesSize);
|
||||||
|
mTilesSize = mTilesCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mTilesSize > mTiles.length - 10) {
|
||||||
|
Log.d(TAG, "realloc tiles");
|
||||||
|
MapTile[] tmp = new MapTile[mTiles.length + 10];
|
||||||
|
System.arraycopy(mTiles, 0, tmp, 0, mTilesCount);
|
||||||
|
mTiles = tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mTiles[mTilesSize++] = tile;
|
||||||
|
mTilesCount++;
|
||||||
|
}
|
||||||
|
|
||||||
private void clearTile(MapTile t) {
|
private void clearTile(MapTile t) {
|
||||||
if (t == null)
|
if (t == null)
|
||||||
return;
|
return;
|
||||||
@ -506,7 +512,6 @@ public class TileManager {
|
|||||||
MapTile t = tiles[i];
|
MapTile t = tiles[i];
|
||||||
if (t != null && t.state == STATE_NEW_DATA) {
|
if (t != null && t.state == STATE_NEW_DATA) {
|
||||||
if (!t.isLocked()) {
|
if (!t.isLocked()) {
|
||||||
|
|
||||||
clearTile(t);
|
clearTile(t);
|
||||||
tiles[i] = null;
|
tiles[i] = null;
|
||||||
remove--;
|
remove--;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user