|
|
@ -212,10 +212,10 @@ public class Photo { |
|
|
|
image = tmp; |
|
|
|
} |
|
|
|
|
|
|
|
public async void UnloadAsync() { |
|
|
|
public async void Unload() { |
|
|
|
Loaded = false; |
|
|
|
if (texture != placeholder) { |
|
|
|
await Task.Run( () => { texture.Dispose(); }); |
|
|
|
texture.Dispose(); |
|
|
|
texture = placeholder; |
|
|
|
} |
|
|
|
} |
|
|
@ -812,7 +812,7 @@ public class Game : GameWindow { |
|
|
|
int minLoadedImage = Math.Max(0, photoIndex - 20); |
|
|
|
int maxLoadedImage = Math.Min(photoIndex + 20, photos.Count - 1); |
|
|
|
// First, unload images that haven't been touched in a while.
|
|
|
|
// FIXME: also cancel any of these if they still have an in-progress loading task -- I suspect this is the source of a memory leak.
|
|
|
|
// FIXME: also cancel any of these if they still have an in-progress loading task?
|
|
|
|
// FIXME: keep around thumbnail-sized textures?
|
|
|
|
while (loadedImages.Count > 60) { |
|
|
|
long earliestTime = long.MaxValue; |
|
|
@ -825,7 +825,8 @@ public class Game : GameWindow { |
|
|
|
} |
|
|
|
if (earliest != null) { |
|
|
|
Console.WriteLine($"loadedImages.Count: {loadedImages.Count}, evicting {earliest.Filename} @ {earliestTime}"); |
|
|
|
earliest.UnloadAsync(); |
|
|
|
// TODO: we have to free textures on the GL thread, but could we do that async'ly to keep the UI responsive?
|
|
|
|
earliest.Unload(); |
|
|
|
loadedImages.Remove(earliest); |
|
|
|
} |
|
|
|
} |
|
|
|