Read Moose_DynamicGroundBattle_Plugin.lua, lines 540 to 580
Read Moose_DynamicGroundBattle_Plugin.lua, lines 340 to 380
Read Moose_DynamicGroundBattle_Plugin.lua, lines 380 to 430
Now let me check where garrison data cleanup happens:
Read Moose_DynamicGroundBattle_Plugin.lua, lines 470 to 530
Good - I can see some cleanup is already happening. Now let me add comprehensive cleanup to ensure nothing accumulates. I need to add:
Periodic cleanup of old cooldown entries for groups that no longer exist
Cleanup of garrison data for zones that no longer exist or have been recaptured
Ensure marker cleanup is working properly
Moose_DynamicGroundBattle_Plugin.lua+106-5
Perfect! Now all tracking structures have comprehensive cleanup:
Memory Management Summary:
1. spawnedGroups ✓
Cleaned in getAllGroups() when groups are dead
Cleaned in CleanupStaleData() every 10 minutes
2. groupGarrisonAssignments ✓
Cleaned when defenders die in CountAliveDefenders()
Cleaned when rotated out in TryDefenderRotation()
Cleaned in getAllGroups() when groups are dead
Cleaned in CleanupStaleData() every 10 minutes
3. groupAttackCooldown ✓
Cleaned in getAllGroups() when groups are dead
Cleaned in CleanupStaleData() every 10 minutes
4. zoneGarrisons ✓
Dead defenders removed in CountAliveDefenders() (called frequently)
Dead defenders removed in CleanupStaleData() every 10 minutes
Entire garrison data removed if zone no longer exists
lastPatrolTime sub-table cleaned for dead defenders
5. activeMarkers ✓
All markers removed and table cleared every 5 minutes in updateMarkPoints()
Improved to iterate backwards and properly nil out entries
6. Lua Garbage Collection ✓
Forced collectgarbage("collect") in CleanupStaleData() every 10 minutes
Ensures Lua VM reclaims memory from deleted tables
7. Enhanced Memory Logging ✓
Now tracks: Lua memory, Groups, Cooldowns, Garrisons, Defenders
Runs every 15 minutes
Visible in DCS logs for monitoring
All tracking structures now have multiple layers of cleanup to prevent memory accumulation. The combination of immediate cleanup (when groups die) and periodic comprehensive cleanup (every 10 minutes) ensures nothing builds up over long missions.
If no zones are in range, they'll stay as defenders or idle
This prevents the "path too long" error that caused the crash
You can adjust MAX_ATTACK_DISTANCE if needed (lower = more stable, higher = longer range attacks)
New Metrics Added:
Tracked Groups - Total number of groups being managed by the plugin (should match or be close to "Total Active Units")
Lua Memory - Current Lua script memory usage in MB
Warnings:
High memory warning if Lua memory > 500MB
High group count warning if > 200 groups
What to watch for:
Lua Memory steadily increasing over time = memory leak (groups not being cleaned up)
Tracked Groups != Total Active Units = dead groups not being removed from tracking table
Group count approaching MAX limits = might hit spawn caps
This will help you identify if memory is building up before it causes a crash. Check the F10 menu → Show System Statistics periodically during long missions to monitor these values.
✅ Units spawn in friendly zones
✅ Within 15 seconds, get orders to attack nearest enemy zone
✅ Move toward and engage enemy zones
✅ Only become defenders if there are no enemies to attack
✅ Stay focused on attacking unless their home zone is under attack
✅ Can be reassigned new targets every 600 seconds if they stop moving