Principle:Google deepmind Mujoco Rendering Resource Cleanup
| Knowledge Sources | |
|---|---|
| Domains | Memory_Management, Rendering, OpenGL |
| Last Updated | 2026-02-15 06:00 GMT |
Overview
Pattern for properly deallocating visualization and GPU rendering resources to prevent memory and resource leaks.
Description
Rendering Resource Cleanup frees all CPU-side visualization buffers (scene geometries, flex/skin data) and GPU-side rendering resources (textures, shaders, framebuffer objects). mjv_freeScene releases the abstract scene memory while mjr_freeContext releases all OpenGL objects. These must be called before destroying the OpenGL context or terminating GLFW.
Usage
Call during application shutdown, before terminating the window system. Free the scene first, then the rendering context.
Theoretical Basis
Resource cleanup follows the inverse of the initialization order:
# Cleanup order (not real code)
free_scene(scn) # CPU scene buffers
free_context(con) # GPU textures, shaders, FBOs
terminate_window() # GLFW/EGL/OSMesa