Garbage collection setup that might be needed later
All checks were successful
Build Mau & Deploy Mau / build (push) Successful in 1m32s
Build Mau & Deploy Mau / deploy (push) Has been skipped

This commit is contained in:
DTieman
2024-04-19 23:05:56 +02:00
parent 56034b921f
commit d51df88fec
4 changed files with 27 additions and 1 deletions

View File

@@ -99,7 +99,7 @@ public class Room
return _connections.Select(connection => connection.Socket).ToList();
}
private bool IsEmpty()
public bool IsEmpty()
{
return _connections.Count == 0;
}

View File

@@ -31,6 +31,16 @@ public class RoomManager : IRoomManager
{
return Rooms.ContainsKey(roomId);
}
public void ClearGhostRooms()
{
var ghostRooms = Rooms.Where(room => room.Value.IsEmpty());
foreach (var room in ghostRooms)
{
GC.Collect(GC.GetGeneration(room.Value));
RemoveRoom(room.Key);
}
}
}
public interface IRoomManager
@@ -40,4 +50,5 @@ public interface IRoomManager
public List<string> GetAllRooms();
public void RemoveRoom(string roomId);
public bool RoomExists(string roomId);
public void ClearGhostRooms();
}