Dispose of disposable ApiHawk libs when reinitialising
This commit is contained in:
parent
5c89d0cb15
commit
bba4286123
|
@ -5,7 +5,7 @@ using System.Collections.Generic;
|
||||||
|
|
||||||
namespace BizHawk.Client.Common
|
namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
public sealed class ApiContainer
|
public sealed class ApiContainer : IDisposable
|
||||||
{
|
{
|
||||||
public readonly IReadOnlyDictionary<Type, IExternalApi> Libraries;
|
public readonly IReadOnlyDictionary<Type, IExternalApi> Libraries;
|
||||||
|
|
||||||
|
@ -26,5 +26,10 @@ namespace BizHawk.Client.Common
|
||||||
public IToolApi Tool => (IToolApi) Libraries[typeof(IToolApi)];
|
public IToolApi Tool => (IToolApi) Libraries[typeof(IToolApi)];
|
||||||
|
|
||||||
public ApiContainer(IReadOnlyDictionary<Type, IExternalApi> libs) => Libraries = libs;
|
public ApiContainer(IReadOnlyDictionary<Type, IExternalApi> libs) => Libraries = libs;
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
foreach (var lib in Libraries.Values) if (lib is IDisposable disposableLib) disposableLib.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,6 @@ namespace BizHawk.Client.EmuHawk
|
||||||
_apiTypes = list.ToArray();
|
_apiTypes = list.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <remarks>TODO do we need to keep references to these because of GC weirdness? --yoshi</remarks>
|
|
||||||
private static ApiContainer? _container;
|
private static ApiContainer? _container;
|
||||||
|
|
||||||
private static ApiContainer? _luaContainer;
|
private static ApiContainer? _luaContainer;
|
||||||
|
@ -78,8 +77,12 @@ namespace BizHawk.Client.EmuHawk
|
||||||
ToolManager toolManager,
|
ToolManager toolManager,
|
||||||
Config config,
|
Config config,
|
||||||
IEmulator emulator,
|
IEmulator emulator,
|
||||||
IGameInfo game
|
IGameInfo game)
|
||||||
) => new BasicApiProvider(_container = Register( serviceProvider, Console.WriteLine, mainForm, displayManager, inputManager, movieSession, toolManager, config, emulator, game));
|
{
|
||||||
|
_container?.Dispose();
|
||||||
|
_container = Register(serviceProvider, Console.WriteLine, mainForm, displayManager, inputManager, movieSession, toolManager, config, emulator, game);
|
||||||
|
return new BasicApiProvider(_container);
|
||||||
|
}
|
||||||
|
|
||||||
public static ApiContainer RestartLua(
|
public static ApiContainer RestartLua(
|
||||||
IEmulatorServiceProvider serviceProvider,
|
IEmulatorServiceProvider serviceProvider,
|
||||||
|
@ -91,7 +94,11 @@ namespace BizHawk.Client.EmuHawk
|
||||||
ToolManager toolManager,
|
ToolManager toolManager,
|
||||||
Config config,
|
Config config,
|
||||||
IEmulator emulator,
|
IEmulator emulator,
|
||||||
IGameInfo game
|
IGameInfo game)
|
||||||
) => _luaContainer = Register(serviceProvider, logCallback, mainForm, displayManager, inputManager, movieSession, toolManager, config, emulator, game);
|
{
|
||||||
|
_luaContainer?.Dispose();
|
||||||
|
_luaContainer = Register(serviceProvider, logCallback, mainForm, displayManager, inputManager, movieSession, toolManager, config, emulator, game);
|
||||||
|
return _luaContainer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue