java.util.LinkedList clear() improvement

Guy Korland gkorland at gmail.com
Thu Aug 27 14:18:55 UTC 2009


How does it help the GC?
As I understand the M&S algorithm, there's no real advantages in doing so.

In fact in many places to "null" references is considered to be an
anti pattern in java.

Guy

On Thu, Aug 27, 2009 at 4:37 PM, Tom Hawtin<Thomas.Hawtin at sun.com> wrote:
> Guy Korland wrote:
>
>> It seems like linkedList.clear() can be easily fixed to O(1) instead of
>> O(n).
>
> The code is like that on purpose(!). It was done to help GC, in mustang
> IIRC. There really isn't a problem with clear() being O(n) - it's going to
> take at least O(n) to populate it, and in reality *many* times more cycles.
>
> Tom
>



-- 
Guy Korland



More information about the core-libs-dev mailing list