Bug 311 - LinkedList.Clear does not detach nodes
Summary: LinkedList.Clear does not detach nodes
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: master
Hardware: All All
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2011-08-16 21:32 UTC by Todd Foster
Modified: 2011-08-18 13:43 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Demonstrate discrepancy in LinkedList.Clear. (1.07 KB, application/octet-stream)
2011-08-16 21:32 UTC, Todd Foster
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Todd Foster 2011-08-16 21:32:48 UTC
Created attachment 147 [details]
Demonstrate discrepancy in LinkedList.Clear.

LinkedList.Clear discards an entire list without detaching the individual nodes. .NET detaches each node, setting List, Next and Previous to null. 

If I retain a reference to a LinkedListNode<> elsewhere, I expect it to have been detached (and thus to be available for insertion in a different list) after calling .Clear on its previous container.

A demonstration program is attached. It must be built with gmcs. 

Output is as follows:

.NET:

30319.4.0.237

Before clear:
        foo.Value=foo
        foo.List=System.Collections.Generic.LinkedList`1[TestClear.DataType]
        foo.Next=System.Collections.Generic.LinkedListNode`1[TestClear.DataType]
(baz)
        foo.Previous=System.Collections.Generic.LinkedListNode`1[TestClear.DataT
ype](bar)

After clear:
        foo.Value=foo
        foo.List=
        foo.Next=
        foo.Previous=


Mono:

50727.2.0.1433

Before clear:
	foo.Value=foo
	foo.List=System.Collections.Generic.LinkedList`1[TestClear.DataType]
	foo.Next=System.Collections.Generic.LinkedListNode`1[TestClear.DataType](baz)
	foo.Previous=System.Collections.Generic.LinkedListNode`1[TestClear.DataType](bar)

After clear:
	foo.Value=foo
	foo.List=System.Collections.Generic.LinkedList`1[TestClear.DataType]
	foo.Next=System.Collections.Generic.LinkedListNode`1[TestClear.DataType]
	foo.Previous=System.Collections.Generic.LinkedListNode`1[TestClear.DataType]