refactor: memory leaks caused by behaviour collectors fixed

This commit is contained in:
Syntriax 2025-05-29 22:34:01 +03:00
parent 9bf17cc191
commit 67d7f401b8
3 changed files with 1 additions and 11 deletions

View File

@ -7,7 +7,7 @@ namespace Syntriax.Engine.Core;
/// Provides mechanisms for tracking additions and removals, and notifies subscribers when such events occur on the assigned <see cref="IUniverse"/>. /// Provides mechanisms for tracking additions and removals, and notifies subscribers when such events occur on the assigned <see cref="IUniverse"/>.
/// </summary> /// </summary>
/// <typeparam name="T">The type of objects tracked by the collector.</typeparam> /// <typeparam name="T">The type of objects tracked by the collector.</typeparam>
public interface IBehaviourCollector<T> : IHasUniverse, IEnumerable<T> where T : class public interface IBehaviourCollector<T> : IHasUniverse where T : class
{ {
/// <summary> /// <summary>
/// Event triggered when an object of type <typeparamref name="T"/> is added to the collector. /// Event triggered when an object of type <typeparamref name="T"/> is added to the collector.

View File

@ -19,8 +19,6 @@ public class ActiveBehaviourCollector<T> : IBehaviourCollector<T> where T : clas
public IReadOnlyList<T> Behaviours => activeBehaviours; public IReadOnlyList<T> Behaviours => activeBehaviours;
public IUniverse Universe { get; private set; } = null!; public IUniverse Universe { get; private set; } = null!;
public T this[Index index] => activeBehaviours[index];
public ActiveBehaviourCollector() { } public ActiveBehaviourCollector() { }
public ActiveBehaviourCollector(IUniverse universe) => Assign(universe); public ActiveBehaviourCollector(IUniverse universe) => Assign(universe);
@ -119,7 +117,4 @@ public class ActiveBehaviourCollector<T> : IBehaviourCollector<T> where T : clas
OnUnassigned?.Invoke(this); OnUnassigned?.Invoke(this);
return true; return true;
} }
public IEnumerator<T> GetEnumerator() => activeBehaviours.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => activeBehaviours.GetEnumerator();
} }

View File

@ -17,8 +17,6 @@ public class BehaviourCollector<T> : IBehaviourCollector<T> where T : class
public IReadOnlyList<T> Behaviours => behaviours; public IReadOnlyList<T> Behaviours => behaviours;
public IUniverse Universe { get; private set; } = null!; public IUniverse Universe { get; private set; } = null!;
public T this[Index index] => behaviours[index];
public BehaviourCollector() { } public BehaviourCollector() { }
public BehaviourCollector(IUniverse universe) => Assign(universe); public BehaviourCollector(IUniverse universe) => Assign(universe);
@ -98,7 +96,4 @@ public class BehaviourCollector<T> : IBehaviourCollector<T> where T : class
OnUnassigned?.Invoke(this); OnUnassigned?.Invoke(this);
return true; return true;
} }
public IEnumerator<T> GetEnumerator() => behaviours.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => behaviours.GetEnumerator();
} }