From fea80fdb2b5b691628f5889c5c28c3e55eb1f4d3 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Thu, 10 Mar 2005 01:30:34 +0000 Subject: [PATCH] Changed the tileset cache to use soft references. We want the cache because we'd like to use the same TileSet over again when possible, but we don't want to forevermore hold onto a TileSet if it could be gc'd. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3392 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- src/java/com/threerings/media/tile/TileManager.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/java/com/threerings/media/tile/TileManager.java b/src/java/com/threerings/media/tile/TileManager.java index cae7fb805..3b5d46b46 100644 --- a/src/java/com/threerings/media/tile/TileManager.java +++ b/src/java/com/threerings/media/tile/TileManager.java @@ -1,5 +1,5 @@ // -// $Id: TileManager.java,v 1.37 2004/10/28 17:49:02 mdb Exp $ +// $Id$ // // Narya library - tools for developing networked games // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved @@ -21,6 +21,8 @@ package com.threerings.media.tile; +import java.lang.ref.SoftReference; + import java.util.HashMap; import com.samskivert.io.PersistenceException; @@ -107,14 +109,16 @@ public class TileManager String bundle, String imgPath, int width, int height) { String key = bundle + "::" + imgPath; - UniformTileSet uts = (UniformTileSet)_handcache.get(key); + SoftReference ref = (SoftReference) _handcache.get(key); + UniformTileSet uts = (ref == null) ? null + : (UniformTileSet) ref.get(); if (uts == null) { uts = new UniformTileSet(); uts.setImageProvider(_defaultProvider); uts.setImagePath(imgPath); uts.setWidth(width); uts.setHeight(height); - _handcache.put(key, uts); + _handcache.put(key, new SoftReference(uts)); } return uts; }