1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-27 14:12:56 +08:00

Fix memory leaks from download buttons (#5606)

Fix memory leaks from download buttons
This commit is contained in:
Dean Herbert 2019-08-05 11:31:04 +02:00 committed by GitHub
commit bf0f6e1053
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -48,22 +48,24 @@ namespace osu.Game.Online
attachDownload(manager.GetExistingDownload(modelInfo.NewValue)); attachDownload(manager.GetExistingDownload(modelInfo.NewValue));
}, true); }, true);
manager.DownloadBegan += download => manager.DownloadBegan += downloadBegan;
{ manager.DownloadFailed += downloadFailed;
if (download.Model.Equals(Model.Value))
attachDownload(download);
};
manager.DownloadFailed += download =>
{
if (download.Model.Equals(Model.Value))
attachDownload(null);
};
manager.ItemAdded += itemAdded; manager.ItemAdded += itemAdded;
manager.ItemRemoved += itemRemoved; manager.ItemRemoved += itemRemoved;
} }
private void downloadBegan(ArchiveDownloadRequest<TModel> request)
{
if (request.Model.Equals(Model.Value))
attachDownload(request);
}
private void downloadFailed(ArchiveDownloadRequest<TModel> request)
{
if (request.Model.Equals(Model.Value))
attachDownload(null);
}
private ArchiveDownloadRequest<TModel> attachedRequest; private ArchiveDownloadRequest<TModel> attachedRequest;
private void attachDownload(ArchiveDownloadRequest<TModel> request) private void attachDownload(ArchiveDownloadRequest<TModel> request)
@ -126,8 +128,10 @@ namespace osu.Game.Online
if (manager != null) if (manager != null)
{ {
manager.DownloadBegan -= attachDownload; manager.DownloadBegan -= downloadBegan;
manager.DownloadFailed -= downloadFailed;
manager.ItemAdded -= itemAdded; manager.ItemAdded -= itemAdded;
manager.ItemRemoved -= itemRemoved;
} }
State.UnbindAll(); State.UnbindAll();