Back to Coordinator
Workflow 05 / Recycling

Recycling: Shutdown

VRAM Force-Reclaim, mmap Handle Closure, and Shutdown Protocols

Sequence / System Shutdown Sequence
            sequenceDiagram
                participant E as Unreal Engine
                participant SUB as Subsystem
                participant K as Kernel (DLL)
                
                E->>SUB: 1. Deinitialize() / EndPlay()
                SUB->>K: 2. Physically Terminate Task Pumping
                SUB->>K: 3. UnloadModel()
                K->>K: 4. Destroy WebGPU Buffers
                K->>K: 5. Force Disconnect mmap handles
                Note over SUB, K: VRAM fully returned to OS
                K-->>SUB: 6. Confirm Resources Null
                SUB->>SUB: 7. Destroy Singleton Instance
            
02 / Two Cleanup Paths

Path A: Precision Session Release

Reclaim specific VRAM slots when an individual agent is destroyed.

// Call in Agent's EndPlay
Subsystem->ReleaseSession(this);

Path B: Global Unload (Stop Engine)

Mandatory for level transitions to release GBs of locked VRAM.

// Force evacuate all kernel resources
FLiteRtLmUnrealApi::UnloadModel();
03 / Related Concepts
LEAKINGResource residual risks

AI VRAM is not managed by UE5. Failure to unload will result in physical locking of GBs of memory even after exiting PIE, starving subsequent rendering tasks.

PHYSICSmmap Handle Locking

Without UnloadModel, Windows OS will continue to lock the .bin file, preventing you from replacing or deleting the model weights on disk.