Skip to content

Commit

Permalink
Merge pull request #183 from AArnott/fix182
Browse files Browse the repository at this point in the history
Fix reference clearing in `Sequence<T>.Reset()`
  • Loading branch information
AArnott authored Apr 24, 2020
2 parents 8d40d64 + f585292 commit d822e69
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/Nerdbank.Streams.Tests/SequenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ public void GetMemory_Sizes()
Assert.Throws<ArgumentOutOfRangeException>(() => seq.GetMemory(-1));
}

[Fact]
public void Reset_AfterPartialAdvance()
{
var seq = new Sequence<object>(new MockMemoryPool<object> { Contents = { new object[4] } });
seq.Write(new object[3]);
seq.AdvanceTo(seq.AsReadOnlySequence.GetPosition(2));
seq.Reset();
}

[Fact]
public void MemoryPool_ReleasesReferenceOnRecycle()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Nerdbank.Streams/Sequence`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ internal void Assign(T[] array)
/// </summary>
internal void ResetMemory(ArrayPool<T>? arrayPool)
{
this.ClearReferences(this.Start, this.End);
this.ClearReferences(this.Start, this.End - this.Start);
this.Memory = default;
this.Next = null;
this.RunningIndex = 0;
Expand Down

0 comments on commit d822e69

Please sign in to comment.