mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 18:33:20 +08:00
Add disposal, prevent memory leaks
This commit is contained in:
parent
d1e7621298
commit
c46ea7bdef
@ -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,26 +33,20 @@ 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user