From 6e794f18042c13a0e7755477dd6ed17eb02d6c75 Mon Sep 17 00:00:00 2001 From: Kevin Rushforth Date: Tue, 17 Apr 2007 22:13:24 +0000 Subject: Fixed issue 478: Memory leak in TransparencySortController git-svn-id: https://svn.java.net/svn/j3d-core-utils~svn/trunk@161 9497e636-51bd-65ba-982d-a4982e1767a5 --- .../transparency/TransparencySortController.java | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/classes/share/com/sun/j3d/utils/scenegraph/transparency/TransparencySortController.java b/src/classes/share/com/sun/j3d/utils/scenegraph/transparency/TransparencySortController.java index 5acfbd5..7b62b77 100644 --- a/src/classes/share/com/sun/j3d/utils/scenegraph/transparency/TransparencySortController.java +++ b/src/classes/share/com/sun/j3d/utils/scenegraph/transparency/TransparencySortController.java @@ -45,7 +45,7 @@ package com.sun.j3d.utils.scenegraph.transparency; import java.util.Comparator; -import java.util.HashMap; +import java.util.WeakHashMap; import javax.media.j3d.View; /** @@ -61,9 +61,10 @@ import javax.media.j3d.View; * @since Java 3D 1.4 */ public class TransparencySortController { - - private static HashMap comparators = new HashMap(); - + + // Issue 478 - use a WeakHashMap to avoid holding a reference to a View unnecessarily. + private static WeakHashMap comparators = new WeakHashMap(); + /** * Set the comparator for the specified view. * @@ -76,7 +77,7 @@ public class TransparencySortController { * @param comparator the comparator to call */ public static void setComparator(View view, Comparator comparator) { - comparators.put(view, comparator); + comparators.put(view, comparator); } /** @@ -86,13 +87,6 @@ public class TransparencySortController { * is no comparator for the view or the view is unknown. */ public static Comparator getComparator(View view) { - Object ret = null; - - ret = comparators.get(view); - - if (ret!=null) - return (Comparator)ret; - - return null; + return comparators.get(view); } } -- cgit v1.2.3