mirror of
https://github.com/ppy/osu.git
synced 2025-02-13 12:43:16 +08:00
Fix incorrect delgate capture leading to slow leak of audio tracks
During profile, it was found that the `Completed` delegate was incorrectly also capturing `lastTrack`, leading to an unexpected reference chain that led to a memory leak over a long period of time. This solves the issue by moving the delegate construction to its own method, where it won't capture the other variables.
This commit is contained in:
parent
83a1d39f80
commit
842d508aee
@ -342,11 +342,9 @@ namespace osu.Game.Overlays
|
||||
|
||||
private void changeTrack()
|
||||
{
|
||||
var queuedTrack = getQueuedTrack();
|
||||
|
||||
var lastTrack = CurrentTrack;
|
||||
|
||||
var queuedTrack = new DrawableTrack(current.LoadTrack());
|
||||
queuedTrack.Completed += () => onTrackCompleted(current);
|
||||
|
||||
CurrentTrack = queuedTrack;
|
||||
|
||||
// At this point we may potentially be in an async context from tests. This is extremely dangerous but we have to make do for now.
|
||||
@ -370,6 +368,15 @@ namespace osu.Game.Overlays
|
||||
});
|
||||
}
|
||||
|
||||
private DrawableTrack getQueuedTrack()
|
||||
{
|
||||
// Important to keep this in its own method to avoid inadvertently capturing unnecessary variables in the callback.
|
||||
// Can lead to leaks.
|
||||
var queuedTrack = new DrawableTrack(current.LoadTrack());
|
||||
queuedTrack.Completed += () => onTrackCompleted(current);
|
||||
return queuedTrack;
|
||||
}
|
||||
|
||||
private void onTrackCompleted(WorkingBeatmap workingBeatmap)
|
||||
{
|
||||
// the source of track completion is the audio thread, so the beatmap may have changed before firing.
|
||||
|
Loading…
Reference in New Issue
Block a user