Optimise carousel memory usage by unloading off-screen panels

This commit is contained in:
Dean Herbert
2018-09-06 13:27:17 +09:00
parent 9b753bb429
commit e63f60231a
3 changed files with 29 additions and 4 deletions

View File

@ -424,7 +424,7 @@ namespace osu.Game.Screens.Select
float drawHeight = DrawHeight;
// Remove all items that should no longer be on-screen
scrollableContent.RemoveAll(p => p.Y < Current - p.DrawHeight || p.Y > Current + drawHeight || !p.IsPresent);
scrollableContent.RemoveAll(p => p.CanBeRemoved && (p.Y < Current - p.DrawHeight || p.Y > Current + drawHeight || !p.IsPresent));
// Find index range of all items that should be on-screen
Trace.Assert(Items.Count == yPositions.Count);
@ -486,6 +486,15 @@ namespace osu.Game.Screens.Select
updateItem(p, halfHeight);
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
// aggressively dispose "off-screen" items to reduce GC pressure.
foreach (var i in Items)
i.Dispose();
}
private CarouselBeatmapSet createCarouselSet(BeatmapSetInfo beatmapSet)
{
if (beatmapSet.Beatmaps.All(b => b.Hidden))