Author: sco...@google.com Date: Thu Apr 2 13:48:34 2009 New Revision: 5170
Modified: trunk/dev/core/src/com/google/gwt/dev/util/DiskCache.java Log: Hold instances of DiskCache with weak refs to allow early cleanup. Review by: bobv (TBR) Modified: trunk/dev/core/src/com/google/gwt/dev/util/DiskCache.java ============================================================================== --- trunk/dev/core/src/com/google/gwt/dev/util/DiskCache.java (original) +++ trunk/dev/core/src/com/google/gwt/dev/util/DiskCache.java Thu Apr 2 13:48:34 2009 @@ -18,6 +18,7 @@ import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; +import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; @@ -43,16 +44,19 @@ private static class Shutdown implements Runnable { public void run() { - for (DiskCache diskCache : shutdownList) { + for (WeakReference<DiskCache> ref : shutdownList) { try { - diskCache.finalize(); + DiskCache diskCache = ref.get(); + if (diskCache != null) { + diskCache.finalize(); + } } catch (Throwable e) { } } } } - private static List<DiskCache> shutdownList; + private static List<WeakReference<DiskCache>> shutdownList; private boolean atEnd = true; private RandomAccessFile file; @@ -64,9 +68,10 @@ file = new RandomAccessFile(temp, "rw"); file.setLength(0); if (shutdownList == null) { - shutdownList = new ArrayList<DiskCache>(); + shutdownList = new ArrayList<WeakReference<DiskCache>>(); Runtime.getRuntime().addShutdownHook(new Thread(new Shutdown())); } + shutdownList.add(new WeakReference<DiskCache>(this)); } catch (IOException e) { throw new RuntimeException("Unable to initialize byte cache", e); } --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---