Tier 1
Series 6
6D: Static Interruption
"If everyone broadcasts on the emergency frequency, no one can hear the tower. Static Events are global channels. If you turn on a radio (subscribe) but forget to turn it off when you leave the room (unsubscribe), the radio keeps playing forever, creating a "Memory Leak" ghost."
The Concept: Event Life-Cycle
When using static events (Actions), the listener MUST unsubscribe when they are destroyed. If they don't, the Event keeps a reference to the destroyed object, preventing the Garbage Collector from cleaning it up.
OnEnable: Subscribe (+=)
OnDisable: Unsubscribe (-=)
The Golden Rule: Always pair your pluses with minuses.
OnEnable: Subscribe (+=)
OnDisable: Unsubscribe (-=)
The Golden Rule: Always pair your pluses with minuses.
Red Flag Detected
The AI Trap: "The Zombie Signal"
You ask the AI: "Use a static event to tell the UI when the game is paused."
// AI-Generated Code: The Silent Killer
void OnEnable() {
GameManager.OnPause += ShowPauseMenu;
}
// Audit Fail: Where is OnDisable?
// When this object is destroyed, the GameManager
// still tries to talk to it, causing a MissingReferenceException.
This is a "Memory Leak." The GameManager is holding onto a dead UI script forever.
Elite Telemetry
Research shows "Elite" teams achieve 15% faster lead times by keeping AI on a "very tight leash."
- Small Batches Solving one problem at a time prevents logic drift.
- Modular Design Localizing the "blast radius" of AI changes.
- Tight Loops Rapid iteration with constant code review.
The Mechanic's Correction
Corrective Protocol
void OnDisable() {
// Corrected: Hanging up the phone.
GameManager.OnPause -= ShowPauseMenu;
}
Your Pilot Command
> A skilled Mechanic directs the AI to Unsubscribe. You command: "Ensure you unsubscribe from the static event when the object is disabled."