AI Command Lab // Flight Simulator
301F: The Garbage Collector
Initial AI Output (Fragile)
// AI-Generated Code: The Memory Leak
public class MissionUI : MonoBehaviour {
void OnEnable() {
// Audit Fail: This creates a permanent bond!
// Even if this UI is destroyed, the MissionManager
// still tries to send data to it.
MissionManager.OnUpdate += Refresh;
}
}
Initial AI Prompt
"You ask the AI: "Make the UI update whenever the MissionManager changes.""
Pilot Comm Link
Mission Objective: A skilled Pilot directs the AI to use Proper Lifecycle Management.
Optimized Protocol
public class MissionUI : MonoBehaviour {
void OnEnable() => MissionManager.OnUpdate += Refresh;
// Corrected: Severing the link when the UI is disabled
void OnDisable() => MissionManager.OnUpdate -= Refresh;
void Refresh() { /* Update UI logic */ }
}