using System; using XWorld.Framework; namespace XWorld.Server.Host { public sealed class LoadedGameModule { public string GameId { get; } public int Version { get; } public Func CreateRoom { get; private set; } private GameModuleAlc _alc; // 强引用;Unload 时置空 internal LoadedGameModule(string gameId, int version, GameModuleAlc alc, Func 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; } } }