Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix VirtualisedListContainer rows not returning child to pool on disposal #6316

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading