Skip to content

Instantly share code, notes, and snippets.

@akosmaroy
Created February 15, 2013 10:24
Show Gist options
  • Save akosmaroy/4959548 to your computer and use it in GitHub Desktop.
Save akosmaroy/4959548 to your computer and use it in GitHub Desktop.
diff --git a/utils/src/main/java/org/jaitools/tilecache/DiskMemTileCache.java b/utils/src/main/java/org/jaitools/tilecache/DiskMemTileCache.java
index dd31efa..da8c190 100644
--- a/utils/src/main/java/org/jaitools/tilecache/DiskMemTileCache.java
+++ b/utils/src/main/java/org/jaitools/tilecache/DiskMemTileCache.java
@@ -338,6 +338,17 @@ public class DiskMemTileCache extends Observable implements TileCache {
}
/**
+ * Provides a hint that this object will not be used any longer.
+ * The results of accessing the object after a call to dispose()
+ * are undefined.
+ */
+ public void dispose() {
+ stopTilePolling();
+ // destroy the polling thread
+ tilePollingService.shutdown();
+ }
+
+ /**
* Adds a tile to the cache if not already present.
*
* @param owner the image that this tile belongs to
diff --git a/utils/src/main/java/org/jaitools/tiledimage/DiskMemImage.java b/utils/src/main/java/org/jaitools/tiledimage/DiskMemImage.java
index 7d9229d..f039b27 100644
--- a/utils/src/main/java/org/jaitools/tiledimage/DiskMemImage.java
+++ b/utils/src/main/java/org/jaitools/tiledimage/DiskMemImage.java
@@ -330,6 +330,21 @@ public class DiskMemImage
}
/**
+ * Provides a hint that this object will not be used any longer.
+ * The results of accessing the object after a call to dispose()
+ * are undefined.
+ */
+ @Override
+ public void dispose() {
+ super.dispose();
+
+ if (!isUsingCommonCache() && tileCache != null) {
+ tileCache.dispose();
+ tileCache = null;
+ }
+ }
+
+ /**
* Gets a tile for reading. Any changes to the tile's data
* will not be preserved by the cache.
*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment