Avoid keeping ActorInitializers in memory.

The SupportPowerManager and WithSpriteBody trait captured the ActorInitializer in lambda expressions, which keeps it alive as long as the trait. The lambdas didn't need to capture the ActorInitializer, so rejig them to allow the ActorInitializer to be reclaimed after the traits have been created. As the TypeDictionary in the ActorInitializer can be quite large, this helps reduce memory usage.
This commit is contained in:
RoosterDragon
2024-06-15 21:29:38 +01:00
committed by Gustas
parent cac0438d48
commit 34a68cd2ca
2 changed files with 8 additions and 6 deletions

View File

@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits
Self = init.Self;
DevMode = Self.Trait<DeveloperMode>();
TechTree = Self.Trait<TechTree>();
RadarPings = Exts.Lazy(() => init.World.WorldActor.TraitOrDefault<RadarPings>());
RadarPings = Exts.Lazy(() => Self.World.WorldActor.TraitOrDefault<RadarPings>());
init.World.ActorAdded += ActorAdded;
init.World.ActorRemoved += ActorRemoved;