From 6ede239232cade1dbd454d58f4e853366e422099 Mon Sep 17 00:00:00 2001 From: acolyer Date: Fri, 17 Dec 2004 13:25:52 +0000 Subject: [PATCH] incorporate tim peierls suggestion from mailing list --- docs/adk15ProgGuideDB/pertypewithin.xml | 31 +++++++++---------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/docs/adk15ProgGuideDB/pertypewithin.xml b/docs/adk15ProgGuideDB/pertypewithin.xml index e3f5ec0ae..ec099c1fd 100644 --- a/docs/adk15ProgGuideDB/pertypewithin.xml +++ b/docs/adk15ProgGuideDB/pertypewithin.xml @@ -54,21 +54,16 @@ > instances = new HashSet>(); + + // use WeakHashMap for auto-garbage collection of keys + private Map instances = new WeakHashMap(); after(Object o) returning : execution(new(..)) { - instances.add(new WeakReference(o); + instances.put(o,true); } - public Set getInstances() { - Set result = new HashSet(); - for(WeakReference ref : instances) { - if (ref.get() != null) { - result.add(ref.get()); - } - } - return result; + public Set getInstances() { + return instances.keySet(); } } ]]> @@ -95,21 +90,17 @@ pertypewithin(org.xyz..*) { - private Set> instances = new HashSet>(); + // use WeakHashMap for auto-garbage collection of keys + private Map instances = new WeakHashMap(); after(T t) returning : execution(new(..)) { - instances.add(new WeakReference(t); + instances.put(t, true); } public Set getInstances() { - Set result = new HashSet(); - for(WeakReference ref : instances) { - if (ref.get() != null) { - result.add(ref.get()); - } - } - return result; + return instances.keySet(); } + } ]]> -- 2.39.5