diff --git a/encompass-cs/ComponentManager.cs b/encompass-cs/ComponentManager.cs index 8071864..cac8503 100644 --- a/encompass-cs/ComponentManager.cs +++ b/encompass-cs/ComponentManager.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; using Encompass.Exceptions; +using Collections.Pooled; namespace Encompass { @@ -14,7 +15,7 @@ namespace Encompass private readonly Dictionary> entityIDToComponentIDs = new Dictionary>(); private readonly Dictionary componentIDToEntityID = new Dictionary(); - private readonly Dictionary>> entityIDToComponentTypeToComponentIDs = new Dictionary>>(); + private readonly Dictionary>> entityIDToComponentTypeToComponentIDs = new Dictionary>>(); private readonly Dictionary> typeToComponentIDs = new Dictionary>(); @@ -30,7 +31,7 @@ namespace Encompass internal void RegisterEntity(Guid entityID) { entityIDToComponentIDs.Add(entityID, new HashSet()); - entityIDToComponentTypeToComponentIDs.Add(entityID, new Dictionary>()); + entityIDToComponentTypeToComponentIDs.Add(entityID, new PooledDictionary>()); } internal Guid NextID() @@ -199,6 +200,11 @@ namespace Encompass public void RegisterDestroyedEntity(Guid entityID) { entityIDToComponentIDs.Remove(entityID); + + foreach (var pooledDictionary in entityIDToComponentTypeToComponentIDs.Values) + { + pooledDictionary.Dispose(); + } entityIDToComponentTypeToComponentIDs.Remove(entityID); } } diff --git a/encompass-cs/Engine.cs b/encompass-cs/Engine.cs index 7da73df..e8884d0 100644 --- a/encompass-cs/Engine.cs +++ b/encompass-cs/Engine.cs @@ -150,7 +150,6 @@ namespace Encompass newComponentMessage.component = component; SendMessage(newComponentMessage); SendPendingComponentMessage(newComponentMessage); - } return componentID;