Skip to content

Commit

Permalink
Merge pull request #6316 from bdach/fix-virtualised-list-dispose
Browse files Browse the repository at this point in the history
Fix `VirtualisedListContainer` rows not returning child to pool on disposal
  • Loading branch information
peppy committed Jun 26, 2024
2 parents 0bc976f + 201fb43 commit 8882a94
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,20 @@ public void TestNaiveList()
[Test]
public void TestVirtualisedList()
{
ExampleVirtualisedList list = null!;
AddStep("create list", () =>
{
ExampleVirtualisedList list;
Child = list = new ExampleVirtualisedList
{
RelativeSizeAxes = Axes.Both,
};
list.RowData.AddRange(Enumerable.Range(1, 10000).Select(i => $"Item #{i}"));
});
AddStep("replace items", () =>
{
list.RowData.Clear();
list.RowData.AddRange(Enumerable.Range(10001, 10000).Select(i => $"Item #{i}"));
});
}

[Test]
Expand Down
13 changes: 13 additions & 0 deletions osu.Framework/Graphics/Containers/VirtualisedListContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,19 @@ public void Unload()
Visible = false;
LifetimeEnd = double.NegativeInfinity;
}

protected override void Dispose(bool isDisposing)
{
// CompositeDrawable only disposes the child pooled drawable (if any).
// This is generally not what we want for two reasons:
// - We want to try to return the pooled drawable to the pool so that it can be reused.
// Disposing it obviously makes reuse impossible.
// - Secondly, pooled drawables return to pool when they lose their parent.
// Thus, we proactively clear the pool drawable from ourselves here.
Unload();

base.Dispose(isDisposing);
}
}

protected abstract ScrollContainer<Drawable> CreateScrollContainer();
Expand Down

0 comments on commit 8882a94

Please sign in to comment.