Back to Portal
Phase 05 / Resource Cleanup

Shutdown: Release

VRAM Deallocation, Session Destruction, and Physical Unloading Encyclopedia

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

Path A: Precision Session Release

Call when an individual NPC is destroyed to reclaim specific KV slots.

// Call in Actor EndPlay
FLiteRtLmUnrealApi::ReleaseSession(this);

Path B: Global Unload

Call during level transitions to free GBs of VRAM.

// Force evacuate all AI resources
FLiteRtLmUnrealApi::UnloadModel();
03 / Related Concepts
CONTRACTVRAM Return Contract

AI VRAM is not managed by UE5's RHI. Failure to unload will starve the renderer, leading to massive FPS drops in non-AI segments.

PHYSICSmmap Handle Closure

Unloading also unbinds file handles. This ensures you can swap or delete model files in Windows without "File in Use" errors.