change memory usage in map panel
git-svn-id: https://osmand.googlecode.com/svn/trunk@83 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
parent
2669af71a2
commit
30641e9ce6
1 changed files with 19 additions and 7 deletions
|
@ -170,6 +170,8 @@ public class MapPanel extends JPanel implements IMapDownloaderCallback {
|
||||||
|
|
||||||
|
|
||||||
public MapPanel(File fileWithTiles) {
|
public MapPanel(File fileWithTiles) {
|
||||||
|
ImageIO.setUseCache(false);
|
||||||
|
|
||||||
tilesLocation = fileWithTiles;
|
tilesLocation = fileWithTiles;
|
||||||
LatLon defaultLocation = DataExtractionSettings.getSettings().getDefaultLocation();
|
LatLon defaultLocation = DataExtractionSettings.getSettings().getDefaultLocation();
|
||||||
latitude = defaultLocation.getLatitude();
|
latitude = defaultLocation.getLatitude();
|
||||||
|
@ -315,20 +317,30 @@ public class MapPanel extends JPanel implements IMapDownloaderCallback {
|
||||||
String file = getFileForImage(x, y, zoom, map.getTileFormat());
|
String file = getFileForImage(x, y, zoom, map.getTileFormat());
|
||||||
if(cache.get(file) == null){
|
if(cache.get(file) == null){
|
||||||
File en = new File(tilesLocation, file);
|
File en = new File(tilesLocation, file);
|
||||||
if(cache.size() > 1000){
|
if(cache.size() > 100){
|
||||||
ArrayList<String> list = new ArrayList<String>(cache.keySet());
|
ArrayList<String> list = new ArrayList<String>(cache.keySet());
|
||||||
for(int i=0; i<list.size(); i+=2){
|
for(int i=0; i<list.size(); i+=2){
|
||||||
cache.remove(list.get(i));
|
Image remove = cache.remove(list.get(i));
|
||||||
|
remove.flush();
|
||||||
|
}
|
||||||
|
if(log.isInfoEnabled()){
|
||||||
|
log.info("Before running gc on map tiles. Total Memory : " + (Runtime.getRuntime().totalMemory() >> 20) + " Mb. Used memory : "
|
||||||
|
+ ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) >> 20) + " Mb");
|
||||||
|
}
|
||||||
|
System.gc();
|
||||||
|
if(log.isInfoEnabled()){
|
||||||
|
log.info("After running gc on map tiles. Total Memory : " + (Runtime.getRuntime().totalMemory() >> 20) + " Mb. Used memory : "
|
||||||
|
+ ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) >> 20) + " Mb");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!downloader.isFileCurrentlyDownloaded(en)) {
|
if (!downloader.isFileCurrentlyDownloaded(en)) {
|
||||||
if (en.exists()) {
|
if (en.exists()) {
|
||||||
long time = System.currentTimeMillis();
|
// long time = System.currentTimeMillis();
|
||||||
try {
|
try {
|
||||||
cache.put(file, ImageIO.read(en));
|
cache.put(file, ImageIO.read(en));
|
||||||
if (log.isDebugEnabled()) {
|
// if (log.isDebugEnabled()) {
|
||||||
log.debug("Loaded file : " + file + " " + (System.currentTimeMillis() - time) + " ms");
|
// log.debug("Loaded file : " + file + " " + (System.currentTimeMillis() - time) + " ms");
|
||||||
}
|
// }
|
||||||
} catch (IIOException e) {
|
} catch (IIOException e) {
|
||||||
log.error("Eror reading png " + x + " " + y + " zoom : " + zoom, e);
|
log.error("Eror reading png " + x + " " + y + " zoom : " + zoom, e);
|
||||||
}
|
}
|
||||||
|
@ -511,7 +523,7 @@ public class MapPanel extends JPanel implements IMapDownloaderCallback {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateLocationLabel(){
|
private void updateLocationLabel(){
|
||||||
gpsLocation.setText(MessageFormat.format("Lat : {0}, lon : {1}, zoom : {2}", latitude, longitude, zoom));
|
gpsLocation.setText(MessageFormat.format("Lat : {0,number,#.####}, lon : {1,number,#.####}, zoom : {2}", latitude, longitude, zoom));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void fireMapLocationListeners(){
|
protected void fireMapLocationListeners(){
|
||||||
|
|
Loading…
Reference in a new issue