I have applied the suggested fix, as it appears to be sensible, thanks.

However, we now advise using ReferenceMap instead of SoftRefHashMap, as the
latter is severly broken.

Stephen

----- Original Message -----
From: "Eduardo Francos" <[EMAIL PROTECTED]>
> I'm using the SoftRefHashMap to manage images and I get a
> ConcurrentModificationException when I call the purge method.
> Looking at the code I found that the method removes GCed references
> directly from the Map instead of using the iterator's remove method.
> I subclassed SoftRefHashMap and implemented the following change in
> purge that works.
>
> public void purge()
> {
>     Map map = getMap();
>     Set keys = map.keySet();
>     if (keys == null) {
>         return;
>     }
>     for (Iterator i = keys.iterator(); i.hasNext(); ) {
>         Object key = (Object)i.next();
>         Reference ref = (Reference)map.get(key);
>         if (ref.get() == null) {
>             // Fix for ConcurrentModificationException
>             // Previously:
>             // map.remove( key );
>             i.remove();
>             // end ConcurrentModificationException fix
>         }
>     }
> }
>
> Either I was doing something wrong or the fix is required.
>
> Eduardo
>
>
>
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to