mirror of
https://github.com/ppy/osu
synced 2025-01-09 23:59:44 +00: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 readonly BeatmapInfo beatmap;
|
||||||
|
|
||||||
private ScoreManager scores;
|
[Resolved]
|
||||||
private IBindable<RulesetInfo> ruleset;
|
private ScoreManager scores { get; set; }
|
||||||
private IAPIProvider api;
|
|
||||||
|
[Resolved]
|
||||||
|
private IBindable<RulesetInfo> ruleset { get; set; }
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private IAPIProvider api { get; set; }
|
||||||
|
|
||||||
protected override double LoadDelay => 250;
|
protected override double LoadDelay => 250;
|
||||||
|
|
||||||
@ -28,26 +33,20 @@ namespace osu.Game.Online.Leaderboards
|
|||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(ScoreManager scores, IBindable<RulesetInfo> ruleset, IAPIProvider api)
|
private void load()
|
||||||
{
|
{
|
||||||
scores.ItemAdded += scoreChanged;
|
scores.ItemAdded += scoreChanged;
|
||||||
scores.ItemRemoved += scoreChanged;
|
scores.ItemRemoved += scoreChanged;
|
||||||
ruleset.ValueChanged += _ => fetchAndLoadTopScore();
|
ruleset.ValueChanged += _ => fetchAndLoadTopScore();
|
||||||
|
|
||||||
this.ruleset = ruleset.GetBoundCopy();
|
|
||||||
this.scores = scores;
|
|
||||||
this.api = api;
|
|
||||||
|
|
||||||
fetchAndLoadTopScore();
|
fetchAndLoadTopScore();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scoreChanged(ScoreInfo score)
|
private void scoreChanged(ScoreInfo score)
|
||||||
{
|
{
|
||||||
if (score.BeatmapInfoID == beatmap.ID)
|
if (score.BeatmapInfoID == beatmap.ID)
|
||||||
{
|
|
||||||
fetchAndLoadTopScore();
|
fetchAndLoadTopScore();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void fetchAndLoadTopScore()
|
private void fetchAndLoadTopScore()
|
||||||
{
|
{
|
||||||
@ -79,5 +78,16 @@ namespace osu.Game.Online.Leaderboards
|
|||||||
.OrderByDescending(s => s.TotalScore)
|
.OrderByDescending(s => s.TotalScore)
|
||||||
.FirstOrDefault();
|
.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