mirror of
https://github.com/ppy/osu
synced 2025-02-17 02:47:19 +00:00
Add finaliser to WorkingBeatmap
This commit is contained in:
parent
1830362337
commit
8b0aaccfe6
@ -30,7 +30,7 @@ namespace osu.Game.Tests
|
||||
trackStore = audioManager.GetTrackStore(reader);
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose();
|
||||
stream?.Dispose();
|
||||
|
@ -46,6 +46,11 @@ namespace osu.Game.Beatmaps
|
||||
skin = new RecyclableLazy<Skin>(GetSkin);
|
||||
}
|
||||
|
||||
~WorkingBeatmap()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
protected virtual Track GetVirtualTrack()
|
||||
{
|
||||
const double excess_length = 1000;
|
||||
@ -199,22 +204,33 @@ namespace osu.Game.Beatmaps
|
||||
other.track = track;
|
||||
}
|
||||
|
||||
public virtual void Dispose()
|
||||
{
|
||||
background.Recycle();
|
||||
waveform.Recycle();
|
||||
storyboard.Recycle();
|
||||
skin.Recycle();
|
||||
|
||||
beatmapCancellation.Cancel();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Eagerly dispose of the audio track associated with this <see cref="WorkingBeatmap"/> (if any).
|
||||
/// Accessing track again will load a fresh instance.
|
||||
/// </summary>
|
||||
public virtual void RecycleTrack() => track.Recycle();
|
||||
|
||||
#region Disposal
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool isDisposing)
|
||||
{
|
||||
// recycling logic is not here for the time being, as components which use
|
||||
// retrieved objects from WorkingBeatmap may not hold a reference to the WorkingBeatmap itself.
|
||||
// this should be fine as each retrieved comopnent do have their own finalizers.
|
||||
|
||||
// cancelling the beatmap load is safe for now since the retrieval is a synchronous
|
||||
// operation. if we add an async retrieval method this may need to be reconsidered.
|
||||
beatmapCancellation.Cancel();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public class RecyclableLazy<T>
|
||||
{
|
||||
private Lazy<T> lazy;
|
||||
|
@ -137,7 +137,7 @@ namespace osu.Game.Tests.Visual
|
||||
track = audio?.Tracks.GetVirtual(length);
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose();
|
||||
store?.Dispose();
|
||||
|
Loading…
Reference in New Issue
Block a user