Files
AIC-Project/Server/Server.Host/LoadedGameModule.cs
T
2026-07-10 10:24:29 +08:00

32 lines
1.0 KiB
C#

using System;
using XWorld.Framework;
namespace XWorld.Server.Host
{
public sealed class LoadedGameModule
{
public string GameId { get; }
public int Version { get; }
public Func<IGameServerRoom> CreateRoom { get; private set; }
private GameModuleAlc _alc; // 强引用;Unload 时置空
internal LoadedGameModule(string gameId, int version, GameModuleAlc alc, Func<IGameServerRoom> factory)
{
GameId = gameId; Version = version; _alc = alc; CreateRoom = factory;
}
// 卸载并返回 ALC 弱引用,便于上层做 GC 内存回收断言
public WeakReference Unload()
{
var alc = _alc;
_alc = null;
// 切断工厂闭包对 entryType→Assembly→ALC 的引用链;卸载后再调用即抛错
CreateRoom = () => throw new ObjectDisposedException($"GameModule {GameId}@{Version} 已卸载");
var weak = new WeakReference(alc);
alc.Unload();
return weak;
}
}
}