state package:essence-of-live-coding

The internal state of a cell to which runStateC or runStateL has been applied.
Hold a map of registered handle keys and destructors
In this monad, handles can be registered, and their destructors automatically executed. It is basically a monad in which handles are automatically garbage collected.
Like runHandlingStateC, but for whole live programs.
Apply this to your main live cell before passing it to the runtime. On the first tick, it initialises the HandlingState at "no handles". On every step, it does:
  1. Unregister all handles
  2. Register currently present handles
  3. Destroy all still unregistered handles (i.e. those that were removed in the last tick)
Handle the HandlingStateT effect _without_ garbage collection. Apply this to your main loop after calling foreground. Since there is no garbage collection, don't use this function for live coding.