From 30641e9ce6c064f4f35bfcd08519d98d7f81617e Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Wed, 26 May 2010 15:48:34 +0000 Subject: [PATCH] change memory usage in map panel git-svn-id: https://osmand.googlecode.com/svn/trunk@83 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8 --- .../src/com/osmand/swing/MapPanel.java | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/DataExtractionOSM/src/com/osmand/swing/MapPanel.java b/DataExtractionOSM/src/com/osmand/swing/MapPanel.java index 128115af91..52b6e945a5 100644 --- a/DataExtractionOSM/src/com/osmand/swing/MapPanel.java +++ b/DataExtractionOSM/src/com/osmand/swing/MapPanel.java @@ -170,6 +170,8 @@ public class MapPanel extends JPanel implements IMapDownloaderCallback { public MapPanel(File fileWithTiles) { + ImageIO.setUseCache(false); + tilesLocation = fileWithTiles; LatLon defaultLocation = DataExtractionSettings.getSettings().getDefaultLocation(); latitude = defaultLocation.getLatitude(); @@ -315,20 +317,30 @@ public class MapPanel extends JPanel implements IMapDownloaderCallback { String file = getFileForImage(x, y, zoom, map.getTileFormat()); if(cache.get(file) == null){ File en = new File(tilesLocation, file); - if(cache.size() > 1000){ + if(cache.size() > 100){ ArrayList list = new ArrayList(cache.keySet()); for(int i=0; i> 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 (en.exists()) { - long time = System.currentTimeMillis(); +// long time = System.currentTimeMillis(); try { cache.put(file, ImageIO.read(en)); - if (log.isDebugEnabled()) { - log.debug("Loaded file : " + file + " " + (System.currentTimeMillis() - time) + " ms"); - } +// if (log.isDebugEnabled()) { +// log.debug("Loaded file : " + file + " " + (System.currentTimeMillis() - time) + " ms"); +// } } catch (IIOException 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(){ - 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(){