1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 16:12:57 +08:00

Add disposal, prevent memory leaks

This commit is contained in:
smoogipoo 2020-04-07 14:49:24 +09:00
parent d1e7621298
commit c46ea7bdef

View File

@ -15,9 +15,14 @@ namespace osu.Game.Online.Leaderboards
{
private readonly BeatmapInfo beatmap;
private ScoreManager scores;
private IBindable<RulesetInfo> ruleset;
private IAPIProvider api;
[Resolved]
private ScoreManager scores { get; set; }
[Resolved]
private IBindable<RulesetInfo> ruleset { get; set; }
[Resolved]
private IAPIProvider api { get; set; }
protected override double LoadDelay => 250;
@ -28,25 +33,19 @@ namespace osu.Game.Online.Leaderboards
}
[BackgroundDependencyLoader]
private void load(ScoreManager scores, IBindable<RulesetInfo> ruleset, IAPIProvider api)
private void load()
{
scores.ItemAdded += scoreChanged;
scores.ItemRemoved += scoreChanged;
ruleset.ValueChanged += _ => fetchAndLoadTopScore();
this.ruleset = ruleset.GetBoundCopy();
this.scores = scores;
this.api = api;
fetchAndLoadTopScore();
}
private void scoreChanged(ScoreInfo score)
{
if (score.BeatmapInfoID == beatmap.ID)
{
fetchAndLoadTopScore();
}
}
private void fetchAndLoadTopScore()
@ -79,5 +78,16 @@ namespace osu.Game.Online.Leaderboards
.OrderByDescending(s => s.TotalScore)
.FirstOrDefault();
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (scores != null)
{
scores.ItemAdded -= scoreChanged;
scores.ItemRemoved -= scoreChanged;
}
}
}
}