3 Resource Management
SDL3 resources (windows, renderers, textures, fonts, etc.) require explicit cleanup. The safe API provides two approaches:
3.1 Automatic Cleanup with Syntax Forms
The recommended approach uses syntax forms that automatically clean up resources:
with-sdl —
Initialize SDL, run body, quit SDL with-window —
Create window, run body, destroy window with-renderer —
Create renderer, run body, destroy renderer with-window+renderer —
Create both, run body, destroy both
These forms use Racket’s custodian system to ensure resources are freed even if an exception occurs.
3.2 Manual Management
For more control, use the constructor and destructor functions directly:
(sdl-init!) (define win (make-window "Title" 800 600)) (define ren (make-renderer win)) ;; ... use win and ren ... (renderer-destroy! ren) (window-destroy! win) (sdl-quit!)