You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Simon Kitching <si...@ecnetwork.co.nz> on 2003/09/27 08:07:29 UTC

[collections] WeakReferences for CursorableLinkedList

Hi,

The CursorableLinkedList class returns "cursors" which act like
ListIterators except that they continue to work when the list is
modified via other means (unlike ListIterator which throws
ConcurrentModificationException).

Unfortunately, there is one critical difference between "cursors" and
ListIterators; the cursor objects returned *must* be explicitly closed
in order to avoid memory leaks, because the CursorableLinkedList class
keeps a list of the existing cursors.

The attached patch uses weak references to the cursor objects in order
to avoid this problem; with this patch, cursor objects can now
transparently be passed to methods expecting ListIterators.

I noticed that the unit tests for this class also failed to test one
particular concept: that cursors continune to work under concurrent
modification. Given that this is the core functionality of this class, I
have added tests for this.

I hope this patch is acceptable. 

Regards,

Simon



Re: [collections] WeakReferences for CursorableLinkedList

Posted by Stephen Colebourne <sc...@btopenworld.com>.
Patch applied, thanks.

Longer term, I'm sure that a CursorableList decorator would be more useful.
After all, why should this no concurrent mods exception code be limited to a
LinkedList?

Stephen

----- Original Message -----
From: "Simon Kitching" <si...@ecnetwork.co.nz>
To: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
Sent: Saturday, September 27, 2003 7:19 AM
Subject: Re: [collections] WeakReferences for CursorableLinkedList


> Hmm .. something appears to have filtered out the attachments.
> Here they are again, in .tar.gz format this time.
>
> On Sat, 2003-09-27 at 18:07, Simon Kitching wrote:
> > Hi,
> >
> > The CursorableLinkedList class returns "cursors" which act like
> > ListIterators except that they continue to work when the list is
> > modified via other means (unlike ListIterator which throws
> > ConcurrentModificationException).
> >
> > Unfortunately, there is one critical difference between "cursors" and
> > ListIterators; the cursor objects returned *must* be explicitly closed
> > in order to avoid memory leaks, because the CursorableLinkedList class
> > keeps a list of the existing cursors.
> >
> > The attached patch uses weak references to the cursor objects in order
> > to avoid this problem; with this patch, cursor objects can now
> > transparently be passed to methods expecting ListIterators.
> >
> > I noticed that the unit tests for this class also failed to test one
> > particular concept: that cursors continune to work under concurrent
> > modification. Given that this is the core functionality of this class, I
> > have added tests for this.
> >
> > I hope this patch is acceptable.
> >
> > Regards,
> >
> > Simon
> >
> >
> >
> > ______________________________________________________________________
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>


----------------------------------------------------------------------------
----


> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [collections] WeakReferences for CursorableLinkedList

Posted by Stephen Colebourne <sc...@btopenworld.com>.
Patch applied, thanks.

Longer term, I'm sure that a CursorableList decorator would be more useful.
After all, why should this no concurrent mods exception code be limited to a
LinkedList?

Stephen

----- Original Message -----
From: "Simon Kitching" <si...@ecnetwork.co.nz>
To: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
Sent: Saturday, September 27, 2003 7:19 AM
Subject: Re: [collections] WeakReferences for CursorableLinkedList


> Hmm .. something appears to have filtered out the attachments.
> Here they are again, in .tar.gz format this time.
>
> On Sat, 2003-09-27 at 18:07, Simon Kitching wrote:
> > Hi,
> >
> > The CursorableLinkedList class returns "cursors" which act like
> > ListIterators except that they continue to work when the list is
> > modified via other means (unlike ListIterator which throws
> > ConcurrentModificationException).
> >
> > Unfortunately, there is one critical difference between "cursors" and
> > ListIterators; the cursor objects returned *must* be explicitly closed
> > in order to avoid memory leaks, because the CursorableLinkedList class
> > keeps a list of the existing cursors.
> >
> > The attached patch uses weak references to the cursor objects in order
> > to avoid this problem; with this patch, cursor objects can now
> > transparently be passed to methods expecting ListIterators.
> >
> > I noticed that the unit tests for this class also failed to test one
> > particular concept: that cursors continune to work under concurrent
> > modification. Given that this is the core functionality of this class, I
> > have added tests for this.
> >
> > I hope this patch is acceptable.
> >
> > Regards,
> >
> > Simon
> >
> >
> >
> > ______________________________________________________________________
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>


----------------------------------------------------------------------------
----


> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [collections] WeakReferences for CursorableLinkedList

Posted by Simon Kitching <si...@ecnetwork.co.nz>.
Hmm .. something appears to have filtered out the attachments.
Here they are again, in .tar.gz format this time.

On Sat, 2003-09-27 at 18:07, Simon Kitching wrote:
> Hi,
> 
> The CursorableLinkedList class returns "cursors" which act like
> ListIterators except that they continue to work when the list is
> modified via other means (unlike ListIterator which throws
> ConcurrentModificationException).
> 
> Unfortunately, there is one critical difference between "cursors" and
> ListIterators; the cursor objects returned *must* be explicitly closed
> in order to avoid memory leaks, because the CursorableLinkedList class
> keeps a list of the existing cursors.
> 
> The attached patch uses weak references to the cursor objects in order
> to avoid this problem; with this patch, cursor objects can now
> transparently be passed to methods expecting ListIterators.
> 
> I noticed that the unit tests for this class also failed to test one
> particular concept: that cursors continune to work under concurrent
> modification. Given that this is the core functionality of this class, I
> have added tests for this.
> 
> I hope this patch is acceptable. 
> 
> Regards,
> 
> Simon
> 
> 
> 
> ______________________________________________________________________
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org