mirror of
https://github.com/ppy/osu.git
synced 2025-02-22 00:43:25 +08: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);
|
trackStore = audioManager.GetTrackStore(reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Dispose()
|
protected override void Dispose(bool isDisposing)
|
||||||
{
|
{
|
||||||
base.Dispose();
|
base.Dispose();
|
||||||
stream?.Dispose();
|
stream?.Dispose();
|
||||||
|
@ -46,6 +46,11 @@ namespace osu.Game.Beatmaps
|
|||||||
skin = new RecyclableLazy<Skin>(GetSkin);
|
skin = new RecyclableLazy<Skin>(GetSkin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~WorkingBeatmap()
|
||||||
|
{
|
||||||
|
Dispose(false);
|
||||||
|
}
|
||||||
|
|
||||||
protected virtual Track GetVirtualTrack()
|
protected virtual Track GetVirtualTrack()
|
||||||
{
|
{
|
||||||
const double excess_length = 1000;
|
const double excess_length = 1000;
|
||||||
@ -199,22 +204,33 @@ namespace osu.Game.Beatmaps
|
|||||||
other.track = track;
|
other.track = track;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Dispose()
|
|
||||||
{
|
|
||||||
background.Recycle();
|
|
||||||
waveform.Recycle();
|
|
||||||
storyboard.Recycle();
|
|
||||||
skin.Recycle();
|
|
||||||
|
|
||||||
beatmapCancellation.Cancel();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Eagerly dispose of the audio track associated with this <see cref="WorkingBeatmap"/> (if any).
|
/// Eagerly dispose of the audio track associated with this <see cref="WorkingBeatmap"/> (if any).
|
||||||
/// Accessing track again will load a fresh instance.
|
/// Accessing track again will load a fresh instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void RecycleTrack() => track.Recycle();
|
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>
|
public class RecyclableLazy<T>
|
||||||
{
|
{
|
||||||
private Lazy<T> lazy;
|
private Lazy<T> lazy;
|
||||||
|
@ -137,7 +137,7 @@ namespace osu.Game.Tests.Visual
|
|||||||
track = audio?.Tracks.GetVirtual(length);
|
track = audio?.Tracks.GetVirtual(length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Dispose()
|
protected override void Dispose(bool isDisposing)
|
||||||
{
|
{
|
||||||
base.Dispose();
|
base.Dispose();
|
||||||
store?.Dispose();
|
store?.Dispose();
|
||||||
|
Loading…
Reference in New Issue
Block a user