On this page:
3.1 Automatic Cleanup with Syntax Forms
3.2 Manual Management

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:

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!)